I am using Azure mobile service to upload images from android device. I have followed the documentation to upload images successfully. But I can't find any documentation to download the blobs. Code i used to upload blob is here..
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. Has anybody done this? Any help is appreciated.
To use the SAS, you need a sharedAccessPolicy:
var sharedAccessPolicy = {
AccessPolicy: {
Permissions: 'w',
Expiry: azure.date.minutesFromNow(5)
}
}
The sharedAccessPolicy.AccessPolicy.Permissions w' is for uploading while 'r' is for downloading.
Not verified myself yet, but you can try 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 .
Hope it will help.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.