0

I dragged two images onto an HTML5 page. I see the preview. Now I want to submit them to the server WITHOUT using the FormData object (for compatibility reasons).

HTML file

<html>
  <head></head>
  <body>
    <img id="image1"/>
    <img id="image2"/>
    <form id="myform" action="otherpage.php" method="post">
    </form>
  </body>
</html>

After dragging two images onto the page, I see their previews in image1 and image2. In the debugger, I see that the src for image1 is data:image/jpeg;base64,/9j/4AAQSkZ... and the src for image2 is data:image/jpeg;base64,/9j/4AAQSkZJRgA...

Using javascript, I want to submit those two images to otherpage.php. My idea is to create fields, and use their values as the source of the image.

function sendImages() {
var placeForm = document.getElementById('myform');
var textInput; //Create a local object
textInput = document.createElement('input'); //Create first <input> object
textInput.name='file1';
textInput.value=document.getElementById('image1').src; //Assign value to object
placeForm.appendChild(textInput); //Append object to form

textInput = document.createElement('input'); //Create second <input> object
textInput.name='file2';
textInput.value=document.getElementById('image2').src; //Assign value to object
placeForm.appendChild(textInput); //Append object to form

placeForm.submit(); //Send form

}

This results in an enormous memory hit that is cleared only when I shut down the browser or after displaying about:blank.

Why is this?

  • Have you tried setting `type` of the input element? – bvx89 Dec 02 '13 at 21:41
  • Setting the `type` to `text` doesn't help; that is the default after createElement and in any event still results in the memory hit. Setting the `type` to `file` might be a good idea. Will try that. – user712505 Dec 02 '13 at 22:03
  • Actually, setting the input type to `file` didn't work for me, and this explains why: http://stackoverflow.com/questions/15763941/fill-input-file-form-with-javascript – user712505 Dec 03 '13 at 03:33
  • have you tried send to server as data/json not as formdata ? – yussan Mar 30 '17 at 07:16

0 Answers0