Sunday, October 30, 2022

Create a temp URL valid for one minute only for file on Azure Blob Storage

 

How to allow dynamic URL in Azure using c# ?


        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);



From .NET 5, Entity Framework Core provides a method that is available to retrieve the SQL statement from a Linq query without executing it, which can be done by the ToQueryString() method of IQueryable 

No comments: