Quantcast
Channel: Node / React : I can't upload an image with my post with multer - Stack Overflow
Viewing all articles
Browse latest Browse all 2

Answer by spiritwalker for Node / React : I can't upload an image with my post with multer

$
0
0

I don't see the file data gets sent to server from your POST request.

 // object post doesn't have the file data  await POST(ENDPOINTS.CREATE_POST, post);

Consider using FormData

 const submitHandler = async (e) => {    e.preventDefault();    const post = new FormData();    // non form data    formData.append("author_firstname", JSON.parse(localStorage.getItem("user")).user_firstname);    ...    // form data    formData.append("image",    document.getElementById("image").files[0]);    ...    // POST request    await POST(ENDPOINTS.CREATE_POST, post);    // document.location.reload()  };

Viewing all articles
Browse latest Browse all 2

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>