Skip to content
This repository was archived by the owner on Oct 27, 2020. It is now read-only.

Upload: add support for deleting uploaded images #40

@ggailey777

Description

@ggailey777

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:

  1. Delete a blob when the related item is deleted.
  2. 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.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions