locked
How to clone blob in azure storage container with Shared Access Signature? RRS feed

  • Question

  • I have a shared access signature to a container with full permission (read, write, delete, list). After upload a file successfully to storage, I want to create a copy of file in the same container. But, it always throw "The specified resource does not exist" error. My code:

    string sasLink = GetAzureStorageContainerLink();
    _container = new CloudBlobContainer(sasLink);    
    _blob = _container.GetBlobReference("a.txt");
    _uploadTransfer.UploadBlobAsync(_blob, @"C:\a.txt");
    
    CloudBlob blobTarget = container.GetBlockBlobReference("b.txt");
    blobTarget.StartCopyFromBlob(_blob); // This line throws error

    Before implement this feature with SAS, my code run properly with Azure storage credential. My SAS link:

    https://example.blob.core.windows.net/21ff0f11-9c61-46c3-958b-2aa49075277d?st=2014-10-22T06%3A57%3A26Z&se=2014-10-22T08%3A57%3A26Z&sp=rwdl&sr=c&sv=2012-02-12&sig=xs99FZIfJZKf%2FQ1ZqU%2Fl1%2BwmGFjKCsDjJMI0VZLuBRg%3D

    How can I create a copy of blob in same container with SAS?

    Wednesday, October 22, 2014 7:08 AM

Answers

  • Hi,

    You could refer the mentioned code from the following link to create a new BLOB in the container using SAS.

    http://azure.microsoft.com/en-us/documentation/articles/storage-dotnet-shared-access-signature-part-2/

    string blobContent = "This blob was created with a shared access signature granting write permissions to the blob. ";
            MemoryStream msWrite = new MemoryStream(Encoding.UTF8.GetBytes(blobContent));
            msWrite.Position = 0;
            using (msWrite)
            {
                blob.UploadFromStream(msWrite);
            }
            Console.WriteLine("Write operation succeeded for SAS " + sas);
            Console.WriteLine();
        }
        catch (StorageException e)
        {
            Console.WriteLine("Write operation failed for SAS " + sas);
            Console.WriteLine("Additional error information: " + e.Message);
            Console.WriteLine();

    And you could use the copy blob operation to copy the required data.
    You could refer the following link for details:

    http://msdn.microsoft.com/en-us/library/azure/dd894037.aspx

    Regards,Malar.

    Wednesday, October 22, 2014 10:34 AM