Assigning a friendly name to an Azure download

I have looked at the question asked here: Friendly filename when public download Azure blob I am a total azure noob and wouldn't have a clue how to implement any of the answers except this one which looks like something I could handle:

string sasBlobToken = blob.GetSharedAccessSignature(sharedPolicy, new SharedAccessBlobHeaders()
        {
            ContentDisposition = "attachment; filename=" + friendlyFileName
        });


string downloadLink = blob.Uri + sasBlobToken;

My question is how to set the 'sharedpolicy variable correctly? I tried just making a blank one on the line above:

SharedAccessBlobPolicy sharedpolicy = new SharedAccessBlobPolicy();

But I get a permission denied message when clicking the download link. So my question is how to set the sharedpolicy variable correctly?

Answers


The reason you're getting this error is because you are not setting any permissions and permission expiry in your SharedAccessBlobPolicy. Try the following:

            SharedAccessBlobPolicy sharedpolicy = new SharedAccessBlobPolicy()
            {
                Permissions = SharedAccessBlobPermissions.Read,//Read permission because you want to download the file
                SharedAccessExpiryTime = new DateTimeOffset(DateTime.UtcNow.AddHours(1))//The link will expire after 1 hour
            };
            string sasBlobToken = blob.GetSharedAccessSignature(sharedPolicy, new SharedAccessBlobHeaders()
                    {
                        ContentDisposition = "attachment; filename=" + friendlyFileName
                    });


            string downloadLink = blob.Uri + sasBlobToken;

Need Your Help

Fluent NHibernate Decorating an Entity

c# fluent-nhibernate poco

Using POCO and Fluent NHibernate, I would like to have the ability to take an object like User and be able to give it various properties. I would like these objects to be able to focus on their