Using formData in Javascript instead of <form> to upload image



I’m not familiar with the html form method of posting.

I’m trying to upload an image to uploadcare.

<form method="POST" enctype="multipart/form-data"
  <input type="hidden" name="UPLOADCARE_PUB_KEY" value="demopublickey">
  <input type="hidden" name="UPLOADCARE_ACTION" value="">
  <input type="file" name="my-file">

Ive changed this to

formData.append('file', file);
formData.append('UPLOADCARE_ACTION', 'http://localhost:3000/server/file/');

But I am getting an error

{error: "Unexpected token < in JSON at position 0", text: "<form action="http://localhost:3000/server/file/" method="post" id="frm">
      <input type="hidden" name="file" value="XXXXXXXX">
  <input type="submit" value="Proceed">



If you’re using uploading with formData, you need to have a handler which will resubmit the form with file UUID:

I think in your case, the proper way is to use uploads in request. See the documentation here: