GenerateSharedAccessSignature produces "undefined" value for baseURL in Azure javascript...


  • I am developing a Windows 10 Universal app in C# with Visual Studio 2015.  I am trying to save an image to a Microsoft Azure Blob based on the ToDoItem tutorial.  The server script is supposed to return the baseURL for the image, but I keep getting "undefined" which causes a format error for the Uri. 
    Wednesday, September 30, 2015 8:14 PM


All replies

  • Can you please post the code you are using to save the image to blob storage, and whatever is supposed to return the base URL for the image?

    There's probably some configuration information somewhere; please make sure you have specified the storage account information as requested.


    Thursday, October 1, 2015 5:55 AM
  • Here is the Insert javascript code:

    var azure = require('azure');
    var qs = require('querystring');
    var appSettings = require('mobileservice-config').appSettings;
    function insert(item, user, request) {
        // Get storage account settings from app settings. 
        var accountName = appSettings.STORAGE_ACCOUNT_NAME;
        var accountKey = appSettings.STORAGE_ACCOUNT_ACCESS_KEY;
        var host = accountName + '';
        if ((typeof item.containerName !== "undefined") && (
        item.containerName !== null)) {
            // Set the BLOB store container name on the item, which must be lowercase.
            item.containerName = item.containerName.toLowerCase();
            // If it does not already exist, create the container 
            // with public read access for blobs.        
            var blobService = azure.createBlobService(accountName, accountKey, host);
            blobService.createContainerIfNotExists(item.containerName, {
                publicAccessLevel: 'blob'
            }, function(error) {
                if (!error) {
                    // Provide write access to the container for the next 5 mins.        
                    var sharedAccessPolicy = {
                        AccessPolicy: {
                            Permissions: azure.Constants.BlobConstants.SharedAccessPermissions.WRITE,
                            Expiry: new Date(new Date().getTime() + 5 * 60 * 1000)
                    // Generate the upload URL with SAS for the new image.
                    var sasQueryUrl = 
                    item.resourceName, sharedAccessPolicy);
                    // Set the query string.
                    item.sasQueryString = qs.stringify(sasQueryUrl.queryString);
                    // Set the full path on the new new item, 
                    // which is used for data binding on the client. 
                    item.imageUri = sasQueryUrl.baseUrl + sasQueryUrl.path;
                } else {
        } else {
    I have checked the STORAGE_ACCOUNT_NAME and STORAGE_ACCOUNT_ACCESS_KEY in the mobile service and they are correct.

    • Edited by BruCru Thursday, October 1, 2015 2:49 PM
    Thursday, October 1, 2015 2:46 PM
  • blobService.generateSharedAccessSignature returns a string instead of an object containing queryString, baseUrl and path members.

    You might want to try this in your code:

    // Set the query string.
    item.sasQueryString = blobService.generateSharedAccessSignature(item.containerName, item.resourceName, sharedAccessPolicy);
    // Generate the upload URL with SAS for the new image.
    var sasQueryUrl = blobService.getUrl(item.containerName, item.resourceName, item.sasQueryString, true);
    // Set the full path on the new item, 
    // which is used for data binding on the client. 
    item.imageUri = blobService.getUrl(item.containerName, item.resourceName, null, true);

    By the way, the 'storage' module in the 'azure' is out of dated. Would you please try the 'azure-storage' module instead?

    var storage= require('azure-storage');
    var blobService = storage.createBlobService(accountName, accountKey, host);

    • Edited by Yang Xia Tuesday, October 20, 2015 6:30 AM
    Tuesday, October 20, 2015 6:15 AM
  • Thanks for your reply... however, I recreated the Mobile Service and that fixed the issue.
    Wednesday, October 21, 2015 2:26 PM