locked
BLOB Storage! RRS feed

Answers

All replies

  • It's just the Windows Azure Node.js SDK, so look for that documentation.
    Monday, October 22, 2012 7:29 PM
  • So, let's say I have a "Product" class which contains:

    string Name;
    decimal Price;
    Image img;

    When inserting this object into the mobile services table, I would modify the insert script to use Item.img and put that into the BLOB storage. Will it return a path to the file that was just uploaded? If so, I would then store that path  in Item.path and continue with the insert statement.

    When reading from that table, the read script will use the Item.path, retrieve the image and store it in Item.img, then proceed to send that object back to the app.

    Am I on the right track here?


    • Edited by MJFara Tuesday, October 23, 2012 4:09 AM
    Monday, October 22, 2012 7:32 PM
  • Hi,

    That is one way to do it, but it means that you are sending and receiving the image data via your mobile service. Its more efficient to instead have your client application access blob storage directly. You can do this securely using shared access signatures.

    Nick Harris has a -great- blog post about how to do this, but his post does it the hard way by using the REST API (he wrote it before we added support for the azure node sdk):

    http://www.nickharris.net/2012/09/windows-8-how-to-upload-an-image-using-a-blob-storage-sas-generated-by-windows-azure-mobile-services/

    Using the Azure Node SDK, the process should be much easier. To get an idea of the APIs, see here:

    https://github.com/WindowsAzure/azure-sdk-for-node/blob/master/test/services/blob/sharedaccesssignature-tests.js



    • Edited by Paul Batum Wednesday, October 24, 2012 3:01 AM
    • Marked as answer by MJFara Wednesday, October 24, 2012 1:11 PM
    Wednesday, October 24, 2012 2:58 AM
  • Great, thank you Paul.

    So I would only be getting the SAS through mobile services, and would be doing the storage operations via the REST API, correct? Any idea when the Azure Storage Library 1.8 will be released? Would be great to use instead of the raw REST API.

    Wednesday, October 24, 2012 1:11 PM
  • Yep that is correct. In my experience, using the SAS from the client is very straightforward, you basically just PUT to the URI specified and provide a couple of headers. I haven't looked at doing this with the Azure Storage Library yet.
    • Marked as answer by MJFara Wednesday, October 24, 2012 6:36 PM
    Wednesday, October 24, 2012 6:24 PM
  • Thanks, in that case I'll just learn how to use the REST API rather than waiting for the storage library.
    Wednesday, October 24, 2012 6:36 PM
  • Nick's post has the relevant code:

        using (var client = new HttpClient())
        {
            //Get a stream of the media just captured
            using (var fileStream = await media.OpenStreamForReadAsync())
            {
                var content = new StreamContent(fileStream);
                content.Headers.Add("Content-Type", media.ContentType);
                content.Headers.Add("x-ms-blob-type", "BlockBlob");
                using (var uploadResponse = await client.PutAsync(new Uri(todoItem.SAS), content))
                {
                    //TODO: any post processing
                }
            }
        }

    Wednesday, October 24, 2012 7:05 PM
  • Is there any way to use a background transfer in this scenario?

    Wednesday, October 31, 2012 8:23 PM
  • I think so. See here:

    http://social.msdn.microsoft.com/Forums/en-US/winappswithcsharp/thread/8daa2e5d-5d4d-4102-857d-9c2329b7d535

    Tuesday, November 6, 2012 7:02 AM
  • Tried to follow that but I get an error when calling:

    await upload.StartAsync().AsTask(cts.Token, progressCallback);

    Method not allowed (405). (Exception from HRESULT: 0x80190195)

    Tuesday, November 6, 2012 3:03 PM
  • You need to specify the method as PUT (note the above code does a PutAsync()). The forum post I linked to shows how to override the method and add additional headers.
    • Marked as answer by MJFara Tuesday, November 6, 2012 7:27 PM
    Tuesday, November 6, 2012 7:17 PM
  • Got it, Thanks!
    Tuesday, November 6, 2012 7:27 PM