0

I have an Azure Function App that accepts two CSV files and a date string as input (via multipart/form-data) and returns a combined Excel file.

  • The function works correctly when tested locally or when triggered remotely via Postman (using the multipart/form-data content type).
  • However, I encounter issues when trying to test it from the Azure Portal using the Code + Test screen, as well as when calling it from an HTTP trigger in a Logic App.

Function Overview:

  • HTTP trigger (POST)
  • Accepts 2 CSV files and a string date (all via multipart/form-data).

What Works:

  • Testing the function locally or remotely after deploying to Azure using Postman works fine. I pass two base64-encoded CSV files and the date string using multipart/form-data, and the function processes and returns the Excel file as expected.

Issues:

  1. Azure Code + Test screen:

    • When I test the function here, I can’t seem to pass the CSV files and date string properly. I get blank values in the function logs for the inputs, even though the function runs without any errors.
    • I am unsure how to correctly structure the inputs using the Code + Test interface, which uses query input fields. If I pass it as json in the body section, it throws an exception when it tries to read it from the result. If I pass it in the query fields as key value pairs it reads all three values as null without throwing an exception.
  2. Logic App HTTP trigger:

    • When I call the function from my Logic App, I’m using an HTTP action after a Create CSV Table action to pass the CSV files and a date string, but the function does not receive the data correctly. The CSV content and the date string aren’t being parsed as expected by the function.

Questions:

  • How can I properly test the Azure Function using the Code + Test screen in the portal when passing two CSV files and a string date?
  • What is the correct way to structure the HTTP action in a Logic App to send two CSV files and a date string to my Azure Function App using multipart/form-data?

What I’ve Tried:

  • I’ve set the Content-Type to multipart/form-data in the Logic App's HTTP action and used @{body('Create_CSV_Table')} to pass the CSV content, but I’m unsure if I’m constructing the multipart body correctly.
  • I’ve also used logging (_logger.LogInformation) inside the function to check what’s being received, but the fields for the CSV files and the date string are blank when using Code + Test or Logic App, while they show correct values when tested via Postman.

Any guidance on how to structure the request from both the Logic App and the Code + Test screen would be greatly appreciated!

Code to Read the Parameters from the Request:

This is the code I am using to read the parameters from the HTTP request in the Azure Function:

var form = await req.ReadFormAsync();
var file1Base64 = form["file1"];
var file2Base64 = form["file2"];
var stringDate = form["stringDate"];
2
  • What connnector are you using to call function or you are using http action? Commented Oct 11, 2024 at 10:55
  • Yes, I am using the http action Commented Oct 11, 2024 at 11:59

1 Answer 1

1

What is the correct way to structure the HTTP action in a Logic App to send two CSV files and a date string to my Azure Function App using multipart/form-data?

To pass from Logic app follow below design:

Used base64():

enter image description here

Headers:

{
  "Content-Type": "multipart/form-data; boundary=Test"
}

Body:

--Test
Content-Disposition: form-data; name="file1"; filename="file1.csv"
Content-Type: text/csv
@{base64(outputs('Compose'))}
--Test
Content-Disposition: form-data; name="file2"; filename="file2.csv"
Content-Type: text/csv
@{base64(outputs('Compose_2'))}
--Test
Content-Disposition: form-data; name="stringDate"
2024-09-02
--Test--

Full Design:

enter image description here

In compose i have csv data. You can get the csv data from file there. Also refer this Document using json to add multiple files.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.