Content-Length: 275654 | pFad | http://github.com/axios/axios/discussions/6570

24 A problem with pushing array to FormData · axios axios · Discussion #6570 · GitHub
Skip to content

A problem with pushing array to FormData #6570

Answered by urg0
echosssss asked this question in Q&A
Discussion options

You must be logged in to vote

To send an array within FormData using Axios, you have two primary options depending on how you want to handle the data on the server side:

  1. Appending Each Item Individually:
    This method is useful when you want the server to interpret the array as individual key-value pairs.
   const formData = new FormData();
   const array = ['value1', 'value2', 'value3'];

   // Append each item in the array with the same key
   array.forEach((item) => {
     formData.append('key[]', item);
   });
  1. Using JSON.stringify:
    This method is useful when you want to send the entire array as a single entity.
   const formData = new FormData();
   const array = ['value1', 'value2', 'value3'];

   // Append the…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by echosssss
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/axios/axios/discussions/6570

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy