Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8932737
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:22:44+00:00 2026-06-15T09:22:44+00:00

I’m trying to generate a Shared Access Signature for a blob (and use it)

  • 0

I’m trying to generate a Shared Access Signature for a blob (and use it) with the v2.0 of the Windows Azure Storage Client Library.
I started with this sample but it’s for v1.7, and transposing it to 2.0 gives a 404 error.

Here is my actual code :
Server side, to generate the SAS :

var myAccount = CloudStorageAccount.Parse(
                  ConfigurationManager.ConnectionStrings[
                              "AzureStorageConnectionString"].ConnectionString);
var myContainer = myAccount.CreateCloudBlobClient()
                                          .GetContainerReference(containerName);
myContainer.CreateIfNotExists();

string blobName = "Imports/" + DateTime.UtcNow.ToString("yyyy-MM-dd_HH-mm-ss") 
                             + ".zip";
var myBlob = myContainer.GetBlockBlobReference(blobName);
using (var stream = 
 new MemoryStream(System.Text.Encoding.UTF8.GetBytes("Hey, I'm empty for now.")))
{
    myBlob.UploadFromStream(stream);
}

var sharedAccesSignature = myBlob.GetSharedAccessSignature(
                 new Microsoft.WindowsAzure.Storage.Blob.SharedAccessBlobPolicy()
{
   Permissions = 
       Microsoft.WindowsAzure.Storage.Blob.SharedAccessBlobPermissions.Write 
       | Microsoft.WindowsAzure.Storage.Blob.SharedAccessBlobPermissions.Read,
       SharedAccessExpiryTime = DateTime.UtcNow.AddHours(1),
});

return myBlob.Uri.AbsoluteUri + sharedAccesSignature;

It tried many things at client side, resulting sometimes in 404, or 403 server error.
For exemple I tried this (result : 404) :

var blobClient = new CloudBlobClient(new Uri(blobWithSharedAccessSignature));
// blobWithSharedAccessSignature here is : https://azertyuiop.blob.core.windows.net/container1/Imports/2012-12-01_19-43-54.zip?sv=2012-02-12&se=2012-12-01T20%3A43%3A54Z&sr=b&sp=rw&sig=h0bTUk[...]3D
// calling blobWithSharedAccessSignature from a webBrowser works.
// result here is valid for containerName : container1
var container = blobClient.GetContainerReference(containerName);
ICloudBlob blobRef = container.GetBlobReferenceFromServer(blobWithSharedAccessSignature);   ==> error 404
using (var fileStream = File.OpenRead(fileFullPath))
{
    blobRef.UploadFromStream(fileStream);
}

I tried replacing

container.GetBlobReferenceFromServer(blobWithSharedAccessSignature);

by

container.GetBlockBlobReference(blobWithSharedAccessSignature);

I also tried replacing

blobClient = new CloudBlobClient(new Uri(blobWithSharedAccessSignature));

by

blobClient = new CloudBlobClient(new Uri(blobWithSharedAccessSignature), new StorageCredentials(blobWithSharedAccessSignature));

which results in a “403 – forbidden” error.

Can someone help me by giving a full sample in v2 ? Or tell me were’s my mistake ? Thanks !

UPDATE – solution here : (thanks to Sandrino Di Mattia)

// Assuming that blobWithSharedAccessSignature is : 
//  "https://azertyuiop.blob.core.windows.net/container1/Imports/2012-12-01_19-43-54.zip?sv=2012-02-12&se=2012-12-01T20%3A43%3A54Z&sr=b&sp=rw&sig=h0bTUkTR%2FdTF%2BVZgDUuBPHqG%2BiTtFeXK4kepBpDR2AU%3D"
Uri blobUriWithoutCredentials = new Uri(new Uri(blobWithSharedAccessSignature).GetLeftPart(UriPartial.Path));
// here blobUriWithoutCredentials is https://azertyuiop.blob.core.windows.net/container1/Imports/2012-12-01_19-43-54.zip
string credentials = blobWithSharedAccessSignature.Substring(blobWithSharedAccessSignature.IndexOf('?'));
// here credentials is "?sv=2012-02-12&se=2012-12-01T22%3A26%3A55Z&sr=b&sp=rw&sig=Lsk8kLyJ8TFoGNVLbFLftCIXUNlIIRPZalkhoPdUfh8%3D"
var blobClient = new CloudBlobClient(blobUriWithoutCredentials, new StorageCredentials(credentials));
ICloudBlob blobRef = blobClient.GetBlobReferenceFromServer(blobUriWithoutCredentials);
using (var fileStream = File.OpenRead(fileFullPath))
{
    blobRef.UploadFromStream(fileStream);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T09:22:45+00:00Added an answer on June 15, 2026 at 9:22 am

    When initializing the CloudBlobClient you need to pass 2 parameters

    • baseUri: Blob url without SAS, http://test.blob.core.windows.net/temp/Imports/2012-12-01_20-56-52.zip
    • credentials: This should be your SAS without the url, ?sv=2012-02-12&se=2012-12-01T21%3A57%3A56Z&sr=b&sp=rw&sig=5JboXXM1Yeo%2BuI6mb18VbURluo%3D

    Working sample:

    var blobClient = new CloudBlobClient(new Uri(blob.Uri.AbsoluteUri), new StorageCredentials(sharedAccesSignature));
    using (var fileStream = File.OpenRead(fileFullPath))
    {
    
        blobClient.GetBlobReferenceFromServer(new Uri(blob.Uri.AbsoluteUri))
                    .UploadFromStream(fileStream);
    }
    

    Extra tip: You don’t need to get a reference to the container. You can immediately access the blob by calling GetBlobReferenceFromServer on the CloudBlobClient.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I am trying to render a haml file in a javascript response like so:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.