0

I want the user to either take a picture from webcam or upload photo. If he chooses to take a picture, It should load in uploadedFile. I dont know even if this is possible at all. I am open to suggestions.

//I have an image

<img id="photo"> // I am getting this from webcam

//And I have an input of type file upload

<input type="file" name="uploadedFile" id="uploadedFile" accept="image/*">

// Now this image data in photo should go to uploadedFile. Is it possible?
Vicky
  • 657
  • 1
  • 8
  • 16
  • look into http://stackoverflow.com/questions/4998908/convert-data-uri-to-file-then-append-to-formdata – Abhas Tandon May 06 '14 at 10:58
  • Thank you, That helped me to some extent. Still don't know how I can attach achieved blob to the input of type file. – Vicky May 07 '14 at 07:55

1 Answers1

2

It isn't possible.

You can either encode the data as text (eg. base64) and store it in a hidden input, or you can send it to the server using the XMLHttpRequest object instead of a form submission.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
  • I have a service that accepts imageData of type "java.nio.ByteBuffer". Can I convert this "encoded data as text" to "java.nio.ByteBuffer". – Vicky May 07 '14 at 08:00
  • I have no idea what that means (at least in so far as it relates to HTTP). I would *assume* that using a JavaScript `File` object and a `FormData` object with XHR would do the job. – Quentin May 07 '14 at 08:29