I am using an Azure Function that has a HTTP trigger with a route parameter {id} which is the fileId of the JSON file I want to read.
I am using a Blob Input Binding to bind where my JSON files are stored. The JSON files are stored in a container called "conversations" and then in a folder called "Conversation".
An example of a file route is "https://<STORAGE_ACCOUNT_NAME>/conversations/Conversation/8da3d7ad3e35273-1aWpKU4rVghHiTaYkjOjVC-eu%7C0000000.json"
Below is my code.
public static class GetConvo
{
[FunctionName("GetConvo")]
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = "getConvo/{id}")] HttpRequest req,
[Blob("conversations/{id}", FileAccess.Read, Connection = "AzureWebJobsStorage")] string json,
ILogger log, string id)
{
log.LogInformation($"File name: {id}");
if (json == null)
{
log.LogInformation($"File {id} not found");
return new NotFoundResult();
}
else
{
log.LogInformation($"Content: {json}");
}
return new OkObjectResult(JsonConvert.DeserializeObject<Message>(json));
The above code works if I move a JSON file to outside the "Conversation" folder, I can access it and receive a 200OK code.
I have tried changing the Blob input binding path to "conversations/Conversation/{id}" as below but that returns a 404 code.
[FunctionName("GetConvo")]
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = "getConvo/{id}")] HttpRequest req,
[Blob("conversations/Conversation/{id}", FileAccess.Read, Connection = "AzureWebJobsStorage")] string json,
ILogger log, string id)
Is this a blob input path problem?
How would I read JSON files that are in a folder in a blob container using an azure function?
2
Answers
I found out what my error was.
The blob input path was correct. It was a URL encoding problem for:
The
%
was not recognised and required; putting25
after the%
resolved this error:@AjgB, yes the Blob path is incorrect. You need to provide the file extension.
Lets say the file is placed directly in your ‘conversations’ folder. Then your BLOB input bindings should be –
Note the .json in the blob path