gpt4 book ai didi

android - 将 blob 从 azure 移动服务下载到 Android

转载 作者:行者123 更新时间:2023-12-03 00:32:19 27 4
gpt4 key购买 nike

我正在使用 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);
}

我可以看到“downloadToFile()”方法,但仍在寻找一种使用 SAS 进行下载过程的方法。有人做过这个吗?如有任何帮助,我们将不胜感激。

最佳答案

要使用 SAS,您需要一个共享访问策略:

var sharedAccessPolicy = {
AccessPolicy: {
Permissions: 'w',
Expiry: azure.date.​minutesFromNow(5)
}
}

sharedAccessPolicy​.AccessPolicy.​Permissions w'用于上传,'r'用于下载。

我自己还没有验证,但你可以尝试http://inessential.com/2014/04/22/mobile_services_and_blob_storage 。另请参阅 https://code.msdn.microsoft.com/windowsapps/Upload-File-to-Windows-c9169190 处的代码。

希望能有所帮助。

关于android - 将 blob 从 azure 移动服务下载到 Android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34857654/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com