Search code examples
.netazure-functionsazure-storage

InvalidQueryParameterValue : Status: 400 (Value for one of the query parameters specified in the request URI is invalid.)


I am implementing an Azure Function with .net6 that connect to an Azure Storage account to upload and delete some files. This is my Azure Function :

    [FunctionName("StoragePostFunction")]
    public static async Task<IActionResult> Post(
        [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequest req, ILogger log)
    {
        string connection = Environment.GetEnvironmentVariable("AzureWebJobsStorage");
        string containerName = Environment.GetEnvironmentVariable("ContainerName");
        Stream myBlob = new MemoryStream();
        var file = req.Form.Files["File"];
        myBlob = file.OpenReadStream();
        var blobClient = new BlobContainerClient(connection, containerName);
        var blob = blobClient.GetBlobClient(file.FileName);
        await blob.UploadAsync(myBlob);
        return new OkObjectResult("file uploaded successfylly");
    }

when I test it locally with Postman http://localhost:7211/api/StoragePostFunction, it works fine. But when I publish this Azure Function and test it with postman it gives me this

error Status: 400 (Value for one of the query parameters specified in the request URI is invalid.)
ErrorCode: InvalidQueryParameterValue

enter image description here

Can anyone help me please ?


Solution

  • Converting my comments into answer to help the community

    After publishing the code to function app, you need to add the environment variable in App settings of Environment Variables Blade as shown below.

    enter image description here

    After adding the environment variables, I am able to get the output.

    enter image description here

    Please note, local.settings file doesn't get deployed while publishing to function app, so you need to add the environment variables in App settings.