azure-sdk-for-net
azure-sdk-for-net copied to clipboard
[BUG] DownloadToAsync InvalidQueryParameterValue comp
Library name and version
Azure.Storage.Blobs 12.13.1
Describe the bug
We've enabled Azure Event Grid to receive notifications of new files created within Blob Storage so we can retrieve file content and report it to other systems. From the notification, we receive the subject which behaves as the container and blob name identifiers.
We're declaring a BlobContainerClient
using storage account access keys and then routing this along with the blob subject to a method for retrieving the content and downloading it to a pre-determined file path. However, when we download the file using the package methods, it's returning a query parameter error related to settings that don't appear to be exposed.
Is there a setup component that I'm missing or is there something amiss in the DownloadToAsync
method for retrieving blobs?
Executing Code
/// <summary>
/// Download file from Azure Storage Blob Container and move to specified directory.
/// </summary>
/// <param name="blobContainerClient">The Blob Container Client</param>
/// <param name="blobFileName">The Blob File Name</param>
/// <param name="outputFilePath">The Output File Directory Path</param>
/// <returns></returns>
public static async Task DownloadFileToDirectoryAsync(BlobContainerClient blobContainerClient, string blobFileName, string outputFilePath)
{
var blobName = blobFileName.Split('/').Last();
var outputFileName = Path.Combine(outputFilePath, blobName);
BlobClient blob = blobContainerClient.GetBlobClient(blobName);
//Download to temporary file
var tempFileName = Path.GetTempFileName();
await blob.DownloadToAsync(tempFileName);
//Move to watched directory.
//This is done because Move is an atomic operation and watchers will not fail to access or try to access a partially written file
File.Move(tempFileName, outputFileName);
}
Logging Details 2022-09-19 20:05:46.724 -04:00 [ERR] Unable to Download blob Azure.RequestFailedException: Value for one of the query parameters specified in the request URI is invalid. RequestId:{REQUEST_ID} Time:2022-09-20T00:05:46.7090104Z 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:{REQUEST_ID} Time:2022-09-20T00:05:46.7090104Z</Message><QueryParameterName>comp</QueryParameterName><QueryParameterValue /><Reason /></Error>
Headers: Server: Microsoft-HTTPAPI/2.0 x-ms-request-id: {REQUEST_ID} x-ms-client-request-id: {CLIENT_REQUEST_ID} x-ms-error-code: InvalidQueryParameterValue Date: Tue, 20 Sep 2022 00:05:45 GMT Content-Length: 351 Content-Type: application/xml
Expected behavior
Blob should be successfully downloaded to the temporary file from the DownloadToAsync
method and then copied to the local watched directory via the File.Move
.
Actual behavior
Blob fails to download due the the comp
query parameter within the DownloadToAsync
method.
Reproduction Steps
Setup a storage account and declare a BlobContainerClient using the storage account's access keys. Then use the below C# code snippet to attempt to download a blob from the container and move it to a local directory.
/// <summary>
/// Download file from Azure Storage Blob Container and move to specified directory.
/// </summary>
/// <param name="blobContainerClient">The Blob Container Client</param>
/// <param name="blobFileName">The Blob File Name</param>
/// <param name="outputFilePath">The Output File Directory Path</param>
/// <returns></returns>
public static async Task DownloadFileToDirectoryAsync(BlobContainerClient blobContainerClient, string blobFileName, string outputFilePath)
{
var blobName = blobFileName.Split('/').Last();
var outputFileName = Path.Combine(outputFilePath, blobName);
BlobClient blob = blobContainerClient.GetBlobClient(blobName);
//Download to temporary file
var tempFileName = Path.GetTempFileName();
await blob.DownloadToAsync(tempFileName);
//Move to watched directory.
//This is done because Move is an atomic operation and watchers will not fail to access or try to access a partially written file
File.Move(tempFileName, outputFileName);
}
Environment
Windows on .NET 5 both in local runtime environments and under server hosting bundle.
Thank you for your feedback. This has been routed to the support team for assistance.
Looks like "comp=" value is blank
<?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:{REQUEST_ID} Time:2022-09-20T00:05:46.7090104Z</Message><QueryParameterName>comp</QueryParameterName>**<QueryParameterValue />**<Reason /></Error>
At the same time it's not expected us to send this query parameter for the DownloadTo
API. Could we get some SDK client side logging so we can see how the request is being form and being sent to the service? Looks like the URL is getting formed incorrectly when attempting to download.
https://learn.microsoft.com/en-us/dotnet/azure/sdk/logging#configure-custom-logging
@gravity-tthrockmorton Thanks for reaching out to us and sharing this feedback. Please check the suggestion in the above comment. Also could you please share the Server Request Id ( that you got in the error message) ? so that I can look in our backend logs for the cause of the failure.
@gravity-tthrockmorton I wanted to do quick follow-up to check if you had a chance to look at the above comments. Please let us know if you had any updates on this. Awaiting your reply.
@gravity-tthrockmorton The action is currently pending on you to follow the above suggestion and also share the failing Server Request ID. If you need any further assistance on this issue in future, please feel free to reopen this thread. We would be happy to help.