[英]Download blobs from azure mobile service to android
I am using Azure mobile service to upload images from android device. 我正在使用Azure移动服务从android设备上传图像。 I have followed the documentation to upload images successfully.
我已经按照文档成功上传了图像。 But I can't find any documentation to download the blobs.
但是我找不到任何文档来下载Blob。 Code i used to upload blob is here..
我用来上传Blob的代码在这里。
public void uploadPhoto() {
if (MainActivity.mClient == null) {
return;
}
final Assignment_Attachment item = new Assignment_Attachment();
item.setAttachementIdentifier(attachmentUniqueIdentifier);
item.setFilename(MAP_FILE_NAME_KEY);
item.setContainerName("schoolonlineblobattachment");
// Use a unigue GUID to avoid collisions.
UUID uuid = UUID.randomUUID();
String uuidInString = uuid.toString();
item.setResourceName(uuidInString);
// Send the item to be inserted. When blob properties are set this
// generates a SAS in the response.
AsyncTask<Void, Void, Void> task = new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
try {
final Assignment_Attachment entity = addItemInTable(item);
Log.d("sasquerystring", "sasquerystring" + entity.getSasQueryString());
// If we have a returned SAS, then upload the blob.
if (entity.getSasQueryString() != null) {
// Get the URI generated that contains the SAS
// and extract the storage credentials.
StorageCredentials cred = new StorageCredentialsSharedAccessSignature(entity.getSasQueryString());
URI imageUri = new URI(entity.getImageUri());
// Upload the new image as a BLOB from a stream.
CloudBlockBlob blobFromSASCredential = new CloudBlockBlob(imageUri, cred);
blobFromSASCredential.uploadFromFile(DATA_FOR_UPLOAD);
}
runOnUiThread(new Runnable() {
@Override
public void run() {
}
});
} catch (final Exception e) {
}
return null;
}
@Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
//other logic here
}
};
runAsyncTask(task);
}
I can see a "downloadToFile()" method, but still searching a way to use the SAS thing for download process. 我可以看到“ downloadToFile()”方法,但仍在寻找一种使用SAS东西进行下载过程的方法。 Has anybody done this?
有人这样做吗? Any help is appreciated.
任何帮助表示赞赏。
To use the SAS, you need a sharedAccessPolicy: 要使用SAS,您需要一个sharedAccessPolicy:
var sharedAccessPolicy = {
AccessPolicy: {
Permissions: 'w',
Expiry: azure.date.minutesFromNow(5)
}
}
The sharedAccessPolicy.AccessPolicy.Permissions w' is for uploading while 'r' is for downloading. sharedAccessPolicy.AccessPolicy。权限w'用于上传,而'r'用于下载。
Not verified myself yet, but you can try http://inessential.com/2014/04/22/mobile_services_and_blob_storage . 尚未验证自己,但您可以尝试http://inessential.com/2014/04/22/mobile_services_and_blob_storage 。 See also the code at https://code.msdn.microsoft.com/windowsapps/Upload-File-to-Windows-c9169190 .
另请参见https://code.msdn.microsoft.com/windowsapps/Upload-File-to-Windows-c9169190上的代码。
Hope it will help. 希望它会有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.