Azure Blob Storage Temporary File URL
Asked Answered
T

2

5

I have saved pdf files in azure blob storage blob, I want to show these files on my website but when a file render on html its link should be deactivated means no one can use that link to download the file again. Is this possible in azure blob storage?

Teryl answered 20/4, 2020 at 10:18 Comment(1)
There are many articles related to this all over internet. e.g.: learn.microsoft.com/en-us/azure/storage/blobs/… Have a look and ask question like where are you stuck or what problemsyou're facing etc.Leone
B
14

You can use the blob policy to make it:

        CloudStorageAccount account = CloudStorageAccount.Parse("yourStringConnection");
        CloudBlobClient serviceClient = account.CreateCloudBlobClient();

        var container = serviceClient.GetContainerReference("yourContainerName");
        container
            .CreateIfNotExistsAsync()
            .Wait();

        CloudBlockBlob blob = container.GetBlockBlobReference("test/helloworld.txt");
        blob.UploadTextAsync("Hello, World!").Wait();

        SharedAccessBlobPolicy policy = new SharedAccessBlobPolicy();

        // define the expiration time
        policy.SharedAccessExpiryTime = DateTime.UtcNow.AddMinutes(1);

        // define the permission
        policy.Permissions = SharedAccessBlobPermissions.Read;

        // create signature
        string signature = blob.GetSharedAccessSignature(policy);

        // get full temporary uri
        Console.WriteLine(blob.Uri + signature);
Beefwood answered 3/7, 2020 at 17:55 Comment(0)
Q
1

If I understand correctly, you're looking for single use links to Azure Blobs. Natively this feature is not available in Azure Storage. You would need to write code to implement something like this where you would keep track of the number of times a link has been used and in case the limit exceeds, you will not process that link.

Quotha answered 20/4, 2020 at 10:30 Comment(6)
How can i keep track the number of times a link has been used? if someone try to use my storage file link on browser tab then how it is possible to validate it?Teryl
Please use the below link it is very helpful to get temporary azure blob file URL with shared access signature. pedro.digitaldias.com/?p=331Teryl
This provides a link that will expire after a certain time and not after certain uses.Quotha
My file take maximum 10 secs to load so i get the url for 30 seconds, so now my file will be access with this url about for about 3 to 5 times.Teryl
If you are willing to take that as an acceptable risk, then yes you can go with Shared Access Signature and provide links that will expire in a short duration.Quotha
For now i have no choice to get generate url for certain uses. If you found something do share it.Teryl

© 2022 - 2024 — McMap. All rights reserved.