Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Format for dynamic connection string for Azure Storage that uses container name and SAS token

I have an API that allows users to upload files to Azure Storage containers. Right now my API allows file uploads, however it allows any user to upload to any container they want. I want to have users only be able to upload to their own container.

To prevent users from accessing all containers, I had the idea of providing users with SAS tokens to limit container access. The issue is that I am not sure how to format the connection string to include the SAS token as well as the container name. My current connection string is in the following format:

DefaultEndpointsProtocol=...;AccountName=...;AccountKey=...;EndpointSuffix=...

I’ve been using this resource to fix the connection string: https://learn.microsoft.com/en-us/azure/storage/common/storage-configure-connection-string however each time I try to edit my own connection string, it either results in the API returning a 500 error or it allows me to access any of the containers and not just the token-specific container. I’ve also tried simply inputting SharedAccessSignature=<access key> as the connection string but it still does not work.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Simply put, you cannot create a connection string for a specific container.

What you can do is share the container specific SAS URL with your customer. What you can do is create a BlobContainerClient using the SAS URL and then upload the file.

For example, if you are using .Net SDK for Azure Blob Storage, the code would be something like:

var containerClient = new BlobContainerClient(sasUrl);
var blockBlobClient = containerClient.GetBlockBlobClient(blobName);
...write code to upload the blob
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading