2012-09-19 46 views
0

Azure的Blob存儲結果從我的Android應用程序的Android下載我嘗試使用以下URL從在Windows Azure Blob存儲下載:http://iclyps.blob.core.windows.net/broadcasts/23_6.mp4從無效文件

得到的文件已損壞,當我從我的應用程序中下載。使用默認的瀏覽器或Chrome下載時發生相同的錯誤。同樣從Easy Downloader應用程序,也會出現相同的錯誤。只有從我的電腦下載或從Android設備(或模擬器)使用Firefox Beta,才能正確檢索文件。

我使用下面的代碼(片斷):

try { 
     HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection(); 

     //set up some things on the connection 
     urlConnection.setRequestMethod("GET"); 
     urlConnection.setDoOutput(true); 

     //and connect! 
     urlConnection.connect(); 

     bis = new BufferedInputStream(urlConnection.getInputStream(), BUFSIZE); 
     bos = new BufferedOutputStream(
       context.openFileOutput(TMPFILE, Context.MODE_PRIVATE), BUFSIZE); 
     /* 
     * Read bytes to the buffer in chunks of BUFSIZE bytes until there is nothing more to read. 
     * Each chunk is written to the output file. 
     */ 
     byte[] buf = new byte[BUFSIZE]; 
     int nBytes = 0; 
     int tBytes = 0; 
     while ((nBytes = bis.read(buf, 0, BUFSIZE)) > 0) { 
      bos.write(buf, 0, nBytes); 
      tBytes += nBytes; 
     } 
     if (tBytes == 0) throw new Exception("no bytes received"); 
     bos.flush(); 
     MobyLog.d(TAG, "download succeeded: #bytes = " + Integer.toString(tBytes)); 
     return true; 
    } catch (Exception e) { 
     MobyLog.e(TAG, "download failed: " + e); 
     context.deleteFile(TMPFILE); // remove possibly present partial file. 
     return false; 
    } finally { 
     if (bis != null) try { bis.close(); } catch (IOException e) {MobyLog.e(TAG, "bis close exception: " + e); }; 
     if (bos != null) try { bos.close(); } catch (IOException e) {MobyLog.e(TAG, "bos close exception: " + e); }; 
    } 

判斷文件示出了原始文件的第一部分(約700K)被重複在損壞的文件的次數,導致無效的mp4文件。

將文件放在另一個網絡服務器(Apache/IIS)上,並從該位置下載文件確實會導致正確的下載。

有沒有人遇到類似的問題執行從Azure下載?有人可以提供解決方案嗎?

乾杯, 哈拉爾...

回答

0

您是否嘗試過在你的Android應用使用azure-sdk-for-java

我們的場景略有不同,因爲我們使用sdk將圖像從blob存儲中拉到自定義android應用程序。但基本面應該是一樣的。

+0

也可能需要檢查文件上的元數據類型。我看到有時會造成問題。 – BrentDaCodeMonkey

+0

我想到了Azure SDK,但這些文件並不總是位於Azure存儲上;很難區分這些情況。 –

+0

文件的Content-Type標籤在所有情況下都是video/mp4。 –