The specified resource name length is not within the permissible limits Azure Blob Storage
Asked Answered
S

1

5

I am getting an error as "The specified resource name length is not within the permissible limits" when I try to upload a blob to my Azure Storage Account.

enter image description here

Below is my code.

private async Task UploadToAzureBlobStorage(string path, string fileName) {
    try {
        if (CloudStorageAccount.TryParse(StorageConnectionString, out CloudStorageAccount cloudStorageAccount)) {
            var cloudBlobClient = cloudStorageAccount.CreateCloudBlobClient();
            var cloudBlobContainer = cloudBlobClient.GetContainerReference(path);
            var cloudBlockBlob = cloudBlobContainer.GetBlockBlobReference(fileName);
            await cloudBlockBlob.UploadFromFileAsync(path);
        }
        else {
            throw new CustomConfigurationException(CustomConstants.NoStorageConnectionStringSettings);
        }
    }
    catch(Exception ex) {
        throw new CustomConfigurationException($ "Error when uploading to blob: {ex.Message}");
    }
}

Anyone else have faced this same issue?

Stationery answered 2/8, 2019 at 14:9 Comment(1)
It's worth checking here for the rules around the naming of containers (and other resources): blogs.msdn.microsoft.com/jmstall/2014/06/12/…Agentive
S
11

Sometimes the error messages can be misleading. I was getting this error when I call the await cloudBlockBlob.UploadFromFileAsync(path); and the reason behind this issue is that, I have provided an invalid parameter to the function cloudBlobClient.GetContainerReference(path);

enter image description here

This happened because of a recent change in the development. I was constantly concentrating on the fileName parameter in the GetBlockBlobReference function, as I thought the problem is with the blob name.

Unfortunately I was wrong and the real issue was with the blob container name where it has some special characters in it, so I had introduced a new parameter schedule to the existing function, and values of this parameter can be daily, weekly, monthly and these are the names of the containers I have configured in the Azure Blob Storage.

private async Task UploadToAzureBlobStorage(string schedule, string path, string fileName) {
    try {
        if (CloudStorageAccount.TryParse(StorageConnectionString, out CloudStorageAccount cloudStorageAccount)) {
            var cloudBlobClient = cloudStorageAccount.CreateCloudBlobClient();
            var cloudBlobContainer = cloudBlobClient.GetContainerReference(schedule);
            var cloudBlockBlob = cloudBlobContainer.GetBlockBlobReference(fileName);
            await cloudBlockBlob.UploadFromFileAsync(path);
        }
        else {
            throw new CustomConfigurationException(CustomConstants.NoStorageConnectionStringSettings);
        }
    }
    catch(Exception ex) {
        throw new CustomConfigurationException($ "Error when uploading to blob: {ex.Message}");
    }
}

enter image description here

Stationery answered 2/8, 2019 at 14:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.