Reputation: 55
I am building locally a Blazor server app which calls an azure function written in python. I am developing both on my local machine using visual studio for the Blazor app and VS code for the python function. The Python is 3.8.7
The Blazor app sends data to the azure function at http://localhost:7071/api/xxxxx using PostAsJsonAsync as json data in the body. I have tested that that works using webhook.site. The JSON data is (mainly) a base64 encoded .wav file.
The call to PostAsJsonAsync seems to be seen by the python azure function and works "a bit" as if I add a parameter to the call I can read it. However the python function always reports the body as being of zero length.
What am I doing wrong?
Upvotes: 1
Views: 2605
Reputation: 4870
Check if you are sending the request like below:
var modelNew = new Model() { Description = "willekeurige klant", Name = "John Doe" }; response = await client.PostAsJsonAsync("api/ModelsApi/", modelNew);
if (response.IsSuccessStatusCode) //check is response succeeded
{
// Do something
}
And, reading it like below:
import logging
import azure.functions as func
def main(req: func.HttpRequest) -> func.HttpResponse:
logging.info('Python HTTP trigger function processed a request.')
name = req.params.get('name')
if not name:
try:
req_body = req.get_json()
except ValueError:
pass
else:
name = req_body.get('name')
if name:
return func.HttpResponse(f"Hello {name}!")
else:
return func.HttpResponse(
"Please pass a name on the query string or in the request body",
status_code=400
)
Check if you are using this code to encode it:
private static string Base64Encode(string plainText)
{
var plainTextBytes = System.Text.Encoding.UTF8.GetBytes(plainText);
return System.Convert.ToBase64String(plainTextBytes);
}
Further, pls consider using files like .wav in Azure Blob Storage and pass it's url location instead of the whole object for better security.
Upvotes: 1