0

I have an Azure Function App (Node.js) function setup with an HTTP trigger and I am trying to access the HTTP request file data but I am unable. There is an HTML form sending a POST request to the URL of my function on my local machine. This is the form:

<form
      type="multipart/form-data"
      action="http://localhost:7071/api/HttpTrigger1"
      method="POST"
    >
      <input type="file" name="file-one" />
      <button>Submit</button>
</form>

Try as I may, the req.body and req.rawBody attributes of the "req" parameter to my HTTP trigger function only seem to contain a string with the name of the file and not any file data whatsoever. I cannot otherwise find any file data in the req object that gets passed to the HTTP trigger function. After reading up here and elsewhere, I really don't see an answer, everything I have tried so far has not worked. Short of passing the base64 file data in the JSON body, is there any way to just access the multipart/form-data file data from an HTTP request?

I found a guide on the internet that addressed this type of situation but their code indicated req.rawBody property would hold the unparsed data which does not seem to be correct. How do I access file data that is sent with the HTTP request in a Function App function?

2 Answers 2

1

You'll need to identify if the incoming request is a multipart request like - req.headers["content-type"] or if you've other way to do so.

Once you've identified that request is multipart/form data you can use libraries like parse-multipart-data or Form-data-packages to parse raw multipart payload.

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

1 Comment

Thanks for the info! I'll set the header if I wind up needing to. Turns out though, I declared type="multipart/form-data" when it should be "enctype=...". Doah!!
0

The form must have "enctype" set to "multipart/form-data" not "type". See below:

<form
  enctype="multipart/form-data"
  action="http://localhost:7071/api/HttpTrigger1"
  method="POST"
>
  <input type="file" name="file-one" />
  <button>Submit</button>
</form>

1 Comment

Please use the Post answer button only for actual answers. You should modify your original question to add additional information.

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.