繁体   English   中英

从Azure移动服务将Blob下载到Android

[英]Download blobs from azure mobile service to android

我正在使用Azure移动服务从android设备上传图像。 我已经按照文档成功上传了图像。 但是我找不到任何文档来下载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,您需要一个sharedAccessPolicy:

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

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上的代码。

希望它会有所帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM