This repository was archived by the owner on Oct 27, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 256
Upload: add support for deleting uploaded images #40
Copy link
Copy link
Open
Labels
Description
I got a suggestion on my blog to include the ability to delete images in the CordovaUploadImages sample.
This would actually not be that hard to do. There are two delete scenarios:
- Delete a blob when the related item is deleted.
- Delete a blob and keep the related item.
Both scenarios can use the same shared function code, which in the first scenario gets called in the delete operation script and the second scenario would require a custom API to delete just the blob. Neither scenario requires an SAS because the delete is done by the service, which has the access keys safely stored in app settings.
The delete code might look something like this:
var azure = require('azure');
var appSettings = require('mobileservice-config').appSettings;
function deleteBlob (item){
// Get storage account settings from app settings.
var accountName = appSettings.STORAGE_ACCOUNT_NAME;
var accountKey = appSettings.STORAGE_ACCOUNT_ACCESS_KEY;
var host = accountName + '.blob.core.windows.net';
var blobService = azure.createBlobService(accountName, accountKey, host);
blobService.deleteBlob(item.containerName, item.resourceName, null, function(error){
// do error handling here.
})
}
NOTE: This is not tested or fully functional code, so please be warned.