azureazure-blob-storageurlencode

How to download files with white space on name on Azure Blob Storage?


I'm trying to download a file from this URL:

https://renatoleite.blob.core.windows.net/mycontainer/documents/Test Document.pdf

The browser is changing the URL to this:

https://renatoleite.blob.core.windows.net/mycontainer/documents/Test%20Document.pdf

My file in the blob storage has the name: Test Document.pdf

So, when I clicks to download, the Azure say that file not exist:

The specified resource does not exist.

Probably because the browser is trying to get the file with "%20" in the name.

How I can solve this?


Solution

  • As far as I know, if you want to upload the file space name by using azure storage api, it will auto encoded the name(replace the space with %20) when uploading it.

    You could see below example:

    I uploaded the Test Document.pdf to the blob storage.

            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
    CloudConfigurationManager.GetSetting("StorageConnectionString"));
    
            // Create the blob client.
            CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
    
            // Retrieve a reference to a container.
            CloudBlobContainer container = blobClient.GetContainerReference("brando");
    
            // Create the container if it doesn't already exist.
            container.CreateIfNotExists();
    
            // Retrieve reference to a blob named "myblob".
            CloudBlockBlob blockBlob = container.GetBlockBlobReference("Test Document.pdf");
    
            // Create or overwrite the "myblob" blob with contents from a local file.
            using (var fileStream = System.IO.File.OpenRead(@"D:\Test Document.pdf"))
            {
                blockBlob.UploadFromStream(fileStream);
            }
    

    Then I suggest you could use storage explorer(right click the properties to see its url) or azure portal to see its url from the blob's property.

    The url like this:

    You could find it replace the space with %20.

    enter image description here