Sending a newly created image using Push Notification to a tile RRS feed

  • Question

  • Hi

    My issue is sending a newly created image using Push Notification to a tile

    My windows 8 App saves data including a photo url to Azure mobile Services.

    When a new record is created an insert script uploads the picture to a blob using SAS (code below) The insert script also sends a push notification.

    Everything works great to this point if I use a fixed url for the picture Example:

    image1src: 'http://name.blob.core.windows.net/admin/widelogo.png'

    But if I try to use the new image url nothing is pushed.

    image1src: item.thumbnailurl

    I think its because the image is not finished uploading to the blob when the script runs. Not sure for the correct approach, set a delay?

    var azure = require('azure'); var qs = require('querystring'); function insert(item, user, request) { var accountName = 'AppName'; var accountKey = 'Key123'; var host = accountName + '.blob.core.windows.net'; var containerName = 'mypictures-' + item.albumid; var pictureRelativePath = '/' + containerName + '/' + item.fileName; var pictureThumbnailRelativePath = '/' + containerName + '/' + item.thumbnailFileName; // Create the container if it does not exist // Use public read access for the blobs, and the SAS to upload var blobService = azure.createBlobService(accountName, accountKey, host); blobService.createContainerIfNotExists(containerName, { publicAccessLevel: 'blob' }, function (error) { if (!error) { // Container exists now define a policy for write access // that starts immediately and expires in 5 mins var sharedAccessPolicy = createAccessPolicy(); // Create the blobs urls with the SAS item.imageurl = createResourceURLWithSAS(accountName, accountKey, pictureRelativePath, sharedAccessPolicy, host); item.thumbnailurl = createResourceURLWithSAS(accountName, accountKey, pictureThumbnailRelativePath, sharedAccessPolicy, host); } else { console.error(error); } request.execute({ success: function() { // Write to the response and then send the notification in the background request.respond(); push.wns.sendTileWideImageAndText01(item.pushnote, {   //   image1src: 'http://name.blob.core.windows.net/admin/widelogo.png',

    image1src: item.thumbnailurl, text1: "New Message", }, { success: function(pushResponse) { console.log("Sent push:", pushResponse); } }); } }); }); } function createResourceURLWithSAS(accountName, accountKey, blobRelativePath, sharedAccessPolicy, host) { // Generate the SAS for your BLOB var sasQueryString = getSAS(accountName, accountKey, blobRelativePath, azure.Constants.BlobConstants.ResourceTypes.BLOB, sharedAccessPolicy); // Full path for resource with SAS return 'https://' + host + blobRelativePath + '?' + sasQueryString; } function createAccessPolicy() { return { AccessPolicy: { Permissions: azure.Constants.BlobConstants.SharedAccessPermissions.WRITE, // Start: use for start time in future, beware of server time skew Expiry: formatDate(new Date(new Date().getTime() + 5 * 60 * 1000)) // 5 minutes from now } }; } function getSAS(accountName, accountKey, path, resourceType, sharedAccessPolicy) { return qs.encode(new azure.SharedAccessSignature(accountName, accountKey) .generateSignedQueryString(path, {}, resourceType, sharedAccessPolicy)); } function formatDate(date) { var raw = date.toJSON(); // Blob service does not like milliseconds on the end of the time so strip return raw.substr(0, raw.lastIndexOf('.')) + 'Z'; }

    • Edited by Andy Sid Monday, June 3, 2013 2:35 AM
    Sunday, June 2, 2013 3:12 AM


  • Andy,

    I think I follow.  There is no way that the thumbnail could be available because your server code does not upload the file.  I assume your client code is uploading the picture to storage.  The thumbnail would not be available until that operation is completed.

    You would need some other method to trigger the push.  For example after the upload is complete call insert on a dummy table (that doesn't store anything) that in turn does the push.

    Make sense?


    Jeff Sanders (MSFT)

    @jsandersrocks - Windows Store Developer Solutions @WSDevSol
    Getting Started With Windows Azure Mobile Services development? Click here
    Getting Started With Windows Phone or Store app development? Click here
    My Team Blog: Windows Store & Phone Developer Solutions
    My Blog: Http Client Protocol Issues (and other fun stuff I support)

    Monday, June 3, 2013 8:35 PM

All replies