[英]download large file from azure blob storage using java/android with progress
[英]Android download from Azure blob storage results in invalid file
在我的Android应用中,我尝试使用以下URL从Windows Azure Blob存储下载: http : //iclyps.blob.core.windows.net/broadcasts/23_6.mp4
当我从应用程序中下载文件时,结果文件已损坏。 当我使用默认的浏览器或Chrome下载它时,会发生相同的错误。 同样从Easy Downloader应用程序中,也会发生相同的错误。 仅从我的PC上下载或从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文件无效。
将文件放在另一台Web服务器(Apache / IIS)上,然后从该位置下载文件确实可以正确下载。
有没有人遇到过类似的问题,需要从Azure执行下载? 有人可以提供解决方案吗?
干杯,哈拉德...
您是否尝试过在Android应用中使用azure-sdk-for-java ?
我们的方案略有不同,因为我们使用sdk将图片从Blob存储中拉出并推送到自定义android应用。 但是基本原理应该相同。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.