POST request not uploading file to the server POST request not uploading file to the server reactjs reactjs

POST request not uploading file to the server


The cookies are managed by the server, not the client. In your case, you are using a cookie with HttpOnly flag. The client side scripting will not allow you to read the value of Cookies as it is a security threat.

In your nodejs application, the server must be sending a Cookie in response. The server must be doing something like this:

// nodejs (express)res.cookie('cookieKey', "value", { maxAge: 900000, httpOnly: true });

notice the httpOnly flag, this flag prevents the cookie to be used by the client-side scripting.

Once you set the cookie in response to your NodeJs (Express) request, your browser should automatically start sending the Cookie with each of your requests.


If the request is cross-origin be sure to add withCredentials: true as a header in the axios request


After successfully getting the cookie/token from the server, pass the token in the header. (depends on how you are securing your API endpoint.)

axios      .post(URL_ATTACHMENT, formData, { headers : { header : token }})      .then(function (response) {        console.log('response', response);      })      .catch(function (err) {        console.log('err', err);      });