从Azure blob存储下载Android导致文件无效



从我的Android应用程序中,我尝试使用以下URL从windows Azure blob存储下载:http://iclyps.blob.core.windows.net/broadcasts/23_6.mp4

当我从应用程序中下载时,生成的文件已损坏。当我使用默认的浏览器或Chrome下载时,也会出现同样的错误。同样在Easy Downloader应用程序中,也会发生同样的错误。只有从我的电脑下载或使用Firefox Beta从Android设备(或模拟器)下载,才能正确检索文件。

我使用以下代码(片段):

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文件无效。

将该文件放在另一个Web服务器(Apache/IIS)上,并从该位置下载该文件确实可以获得正确的下载。

有人在从Azure执行下载时遇到过类似的问题吗?有人能提供解决方案吗?

干杯,哈拉尔。。。

您是否尝试在android应用程序中使用azure sdk for java?

我们的场景略有不同,因为我们使用sdk将图像从blob存储中拉入并推送到自定义的android应用程序。但基本面应该是一样的。

最新更新