2016-06-20 75 views
0

我正在製作一個應用程序,讓用戶使用AWS S3將他們的視頻上傳到我們的最終用戶。我使用服務器來生成簽名的url並將其返回給客戶端(Web瀏覽器),然後客戶端使用該URL上傳到我們的後端。它工作得很好,但我有一個小問題,我們無法跟蹤從瀏覽器啓動的文件上傳進度。使用AWS S3簽名的url獲取上傳進度

那麼有沒有什麼方法可以從我們的服務器上傳進度?

+0

從客戶端執行上傳的過程是什麼? – Jedi

+1

該過程只是將文件正常上傳到從服務器生成的簽名url。據我所知,我可以從瀏覽器上取得進展。但我需要從我的管理面板的服務器獲取它。 – Yoshi

回答

0

Java代碼爲同一

public void uploadtoS3(File file) throws AmazonServiceException, AmazonClientException, InterruptedException { 
     logger.debug("Uploading the File => S3"); 
     ProfileCredentialsProvider credentialProviderChain = new ProfileCredentialsProvider(); 
     TransferManager tx = new TransferManager(credentialProviderChain.getCredentials()); 
     final Upload upload = tx.upload(env.getProperty("amazon.s3.media.bucket"), file.getName(), file); 

     // You can poll your transfer's status to check its progress 
     if (upload.isDone() == false) { 
      logger.debug("Transfer: " + upload.getDescription()); 
      logger.debug("State: " + upload.getState()); 
      logger.debug("Progress: " + upload.getProgress().getBytesTransferred()); 
     } 

     // Transfers also allow you to set a <code>ProgressListener</code> to 
     // receive 
     // asynchronous notifications about your transfer's progress. 

     upload.addProgressListener(new ProgressListener() { 
      // This method is called periodically as your transfer progresses 
      public void progressChanged(ProgressEvent progressEvent) { 
       logger.debug(upload.getProgress().getPercentTransferred() + "%"); 

       if (progressEvent.getEventCode() == ProgressEvent.COMPLETED_EVENT_CODE) { 
        logger.debug("Upload complete!!!"); 
       } 
      } 
     }); 

     // Or you can block the current thread and wait for your transfer to 
     // to complete. If the transfer fails, this method will throw an 
     // AmazonClientException or AmazonServiceException detailing the reason. 
     upload.waitForCompletion(); 

     // After the upload is complete, call shutdownNow to release the 
     // resources. 
     tx.shutdownNow(); 
    } 

還與多上傳作品。

相關問題