This repository is for active development of the Azure SDK for .NET. For consumers of the SDK we recommend visiting our public developer docs at https://learn.microsoft.com/dotnet/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-net.
MIT License
5.16k
stars
4.53k
forks
source link
[BUG] Azure Blob Storage upload threw InvalidQueryParameterValue when using SDK #44807
Have a look at this below code to upload file to Azure Blob Storage. The code use blobServiceClient that registered with DI and use connection string.
public async Task<StorageActionResult> UploadToStorageAsync(string folder, string fileName, string base64Content, CancellationToken cancellationToken)
{
try
{
var container = options.Value.ContainerName;
var containerClient = blobServiceClient.GetBlobContainerClient(container);
await containerClient.CreateIfNotExistsAsync(PublicAccessType.BlobContainer, cancellationToken: cancellationToken);
var blobName = $"{folder}/{Guid.NewGuid()}.{fileName.Split('.')[1]}";
var blobClient = containerClient.GetBlobClient(blobName);
var stream = new MemoryStream(Convert.FromBase64String(base64Content.Split(',')[1]));
await blobClient.UploadAsync(stream, true, cancellationToken);
stream.Close();
return StorageActionResult.Ok(blobClient.GenerateSasUri(BlobSasPermissions.Read, DateTimeOffset.UtcNow.AddDays(9999)).ToString(), blobName);
}
catch (Exception ex)
{
logger.LogError(ex.InnerException, ex.Message);
return StorageActionResult.Error("Errors occurs while uploading to blob storage.");
}
}
when deployed to Azure App Service, the following error occurred while it works on local machine with the same connection string.
Status: 400 (Value for one of the query parameters specified in the request URI is invalid.)
ErrorCode: InvalidQueryParameterValue
Additional Information:
QueryParameterName: comp
QueryParameterValue:
Reason:
Content:
<?xml version="1.0" encoding="utf-8"?><Error><Code>InvalidQueryParameterValue</Code><Message>Value for one of the query parameters specified in the request URI is invalid.
RequestId:0df81bee-f01e-0067-53c2-cac1ff000000
Time:2024-06-30T07:49:59.6604299Z</Message><QueryParameterName>comp</QueryParameterName><QueryParameterValue /><Reason /></Error>
Headers:
Server: Microsoft-HTTPAPI/2.0
x-ms-request-id: 0df81bee-f01e-0067-53c2-cac1ff000000
x-ms-client-request-id: 549f3d2a-7ca9-4fd4-a94a-397096b7d358
x-ms-error-code: InvalidQueryParameterValue
Date: Sun, 30 Jun 2024 07:49:59 GMT
Content-Length: 351
Content-Type: application/xml
Expected behavior
It should upload file to azure blob storage when deployed to azure app service just like how it is working on local machine
Actual behavior
It threw error while uploading file to blob storage.
Reproduction Steps
Simply upload to azure blob storage with connection string
Library name and version
Azure.Storage.Blobs 12.20.0
Describe the bug
Have a look at this below code to upload file to Azure Blob Storage. The code use blobServiceClient that registered with DI and use connection string.
when deployed to Azure App Service, the following error occurred while it works on local machine with the same connection string.
Expected behavior
It should upload file to azure blob storage when deployed to azure app service just like how it is working on local machine
Actual behavior
It threw error while uploading file to blob storage.
Reproduction Steps
Simply upload to azure blob storage with connection string
Environment
No response