0
我一直在Android
OS正在与Azure
,我设法我的视频文件(.MP4)上传到我已经为它准备的容器。Android操作系统 - 如何跟踪Azure的上传进度
- 容器的临时密钥
- 名字的地方,我要发送的文件
- 服务器URI :
我通过获取Shared Access Signature (SAS)
第一,它为我提供了这样做
然后,我开始AsyncTask
使用“上传”将文件发送到容器。
我检查了容器和文件被上传完美,对到底有没有问题。
我的问题是关于上传进度。有没有可能跟踪它?我想有一个上传栏来提供更好的用户体验。
P.S - 我使用的是Azure Mobile SDK
这里是我的代码:
private void uploadFile(String filename){
mFileTransferInProgress = true;
try {
Log.d("Funky Stuff", "Blob Azure Config");
final String gFilename = filename;
File file = new File(filename); // File path
String blobUri = blobServerURL + sharedAccessSignature.replaceAll("\"", "");
StorageUri storage = new StorageUri(URI.create(blobUri));
CloudBlobClient blobCLient = new CloudBlobClient(storage);
//Container name here
CloudBlobContainer container = blobCLient.getContainerReference(blobContainer);
blob = container.getBlockBlobReference(file.getName());
//fileToByteConverter is a method to convert files to a byte[]
byte[] buffer = fileToByteConverter(file);
ByteArrayInputStream inputStream = new ByteArrayInputStream(buffer);
if (blob != null) {
new UploadFileToAzure().execute(inputStream);
}
} catch (StorageException e) {
Log.d("Funky Stuff", "StorageException: " + e.toString());
e.printStackTrace();
} catch (IOException e) {
Log.d("Funky Stuff", "IOException: " + e.toString());
e.printStackTrace();
} catch (Exception e) {
Log.d("Funky Stuff", "Exception: " + e.toString());
e.printStackTrace();
}
mFileTransferInProgress = false;
//TODO: Missing ProgressChanged method from AWS
}
private class UploadFileToAzure extends
AsyncTask <ByteArrayInputStream, Void, Void>
{
@Override
protected Void doInBackground(ByteArrayInputStream... params) {
try {
Log.d("Funky Stuff", "Entered UploadFileToAzure Async" + uploadEvent.mFilename);
//Method to upload, takes an InputStream and a size
blob.upload(params[0], params[0].available());
params[0].close();
} catch (StorageException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
谢谢!
没错多少字节的进展,那说得通!我会试一试!谢谢:d – GuilhermeM
不要忘记接受这个作为答案,如果它的工作原理,因此也将帮助那些有同样的问题 – Ansel
在这个任何更新的人吗? –