0

I need to send one specific image in a form. I mean, there isn't a file picker. I need to use a hidden input to save an image like example.com/myimage.jpg and send it to the form like any other file. I can't change the backend.

var img = new XMLHttpRequest();
img.open("get","favicon.ico",false);
img.send();
document.getElementsByName("image")[0].value=img.response;
//This doesn't work
//The image isn't handle like it does with other files
<form method="POST" enctype="multipart/form-data">
<input name="image" type="hidden" value="IMAGE-HERE">
<input type="submit" value="submit">
</form>
Maxi Os
  • 3
  • 1
  • 2
  • This looks like a duplicate : https://stackoverflow.com/questions/54413227/put-an-image-from-web-on-input-type-hidden – codingbbq Jan 30 '19 at 03:23

2 Answers2

0

With Input type hidden, you can pass data for example say a string like name, age or URL. However to upload a file, What you can try is to use

<input type="file" name"image" id="image" />

and then in your style try to hide the image

#image{
visibility : hidden;
}
codingbbq
  • 4,049
  • 5
  • 35
  • 47
0

Looks like your question was already answered here

It was not possible to set file input value programmatically in the past, but it is possible now

Andrew O.
  • 451
  • 3
  • 8