2017-01-09 34 views
0

我想在將任何圖片上傳到服務器時取得進展。像1%,30%等。 我使用了已經在不同網站上提供的所有解決方案,但我在DataOutputStream的書面閱讀方面取得了進展。上傳圖片時取得進展

Ex。

while (bytesRead > 0) { 
         dos.write(buffer, 0, bufferSize); 
         sentBytes += bufferSize; 
         bytesAvailable = fileInputStream.available(); 
         bufferSize = Math.min(bytesAvailable, maxBufferSize); 
         if (bytesAvailable > 0) { 
          float progress = ((float) sentBytes/(float) totalAvailable) * 100.0f; 
          if (progress % 10 == 0) { 
           publishProgress(sourceFile, (int) progress); 
          } 
         } else { 
          publishProgress(sourceFile, 100); 
         } 
         bytesRead = fileInputStream.read(buffer, 0, bufferSize); 
        } 

在這裏,我即刻獲得100%。但獲得100%後,其仍然上傳圖像在這條線:

 /*Responses from the server (code and message)*/ 
      int serverResponseCode = conn.getResponseCode(); 

我認爲只有這條線只負責上傳圖像。 那麼我怎麼才能得到實際的服務器上傳進度。

服務器端是否有任何要求? 而我的服務器支持

connection.setRequestProperty("Content-Type", "application/octet-stream"); 

請幫我這個。由於

+0

的可能的複製[安卓:對文件上傳進度更新(http://stackoverflow.com/questions/11887149/android-updating- progressbar-for-file-upload) –

回答

2

檢查答案在這裏提供:

你的形象也是一個文件,予以明確。

直接來源指南:

+0

你能否提一提..我的問題在你的鏈接中的解決方案在哪裏? – NehaK

+0

http://delimitry.blogspot.nl/2011/08/android-upload-progress.html –

+0

當然,這並不意味着複製粘貼,因爲這個網站不是在這裏複製粘貼解決方案,而是做一個研究你自己。我們只是指出你正確的方向。 –