Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

8
  • 2
    After posting the files. Do we need to access them from HTTP request or need to access them from parameters on server side. Commented Sep 1, 2017 at 10:53
  • 17
    Thanks for this post, but I still don't see why we need FormData. According to axios's doc, both File and FormData are treated as Browser only, so both ways can be seen equally (github.com/axios/axios#request-config) Commented Dec 17, 2017 at 6:12
  • 4
    Awesome ! I was sending 'data:{ data:formData}' which was generating error 412. It worked with data:formData Commented May 2, 2019 at 0:55
  • 15
    ATTENTION: the snippet works as-is when run in the context of a browser. To run in node.js, one needs to pass the headers computed by formData.getHeaders() This is a known issue with axios; see for e.g. https://github.com/axios/axios/issues/789 Commented May 30, 2019 at 5:10
  • 4
    About the comment by @Hiroki on File vs. FormData: correct me if I'm wrong, but I believe File can be used only if you're uploading a single file and not including any other payload data in the request (like in the answer), but FormData is what you'll have to use if you want to submit a collection of data (that is, a form with several fields) in addition to the file(s) (which I suspect is more often the case in real applications). Commented Feb 26, 2021 at 11:18