Kumar Ravishankar

Kumar Ravishankar

  • 1.8k
  • 437
  • 6.6k

Need to send image data from img element in FormData using Javascript

Aug 1 2022 6:22 AM

< img class="main" src="assets/images/Group 18.jpg"  id="use_current">


I am trying to create FormData to send in xhr request but I am facing issue when appending Image data from img tag.

I tried someting like 

 const aForm = new FormData();

 aForm .append("pipe", "pipeName");

  aForm .append("pipetype", "pipetypeName");

const blob = new Blob(["localhostimagepath"], { type: "multipart/form-data" });

aForm .append("webmasterfile", blob);

  xhr.send(aForm );


But getting error regardinf image data , like invalid image FIle .This needs to be sent as BINARY.

Answers (1)