我正在使用Azure移动服务从Android设备上传图片。 我已按照the documentation成功上传图片。 但我找不到任何下载blob的文档。 用于上传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);
}
我可以看到&#34; downloadToFile()&#34;方法,但仍在搜索使用SAS事物进行下载过程的方法。 有人这样做过吗?任何帮助表示赞赏。
答案 0 :(得分:0)
要使用SAS,您需要sharedAccessPolicy:
onRequestPermissionsResult
sharedAccessPolicy .AccessPolicy。权限w'用于上传,而'r'用于下载。
尚未验证,但您可以尝试http://inessential.com/2014/04/22/mobile_services_and_blob_storage。另请参阅https://code.msdn.microsoft.com/windowsapps/Upload-File-to-Windows-c9169190处的代码。
希望它会有所帮助。