Vicky
Vicky

Reputation: 767

Attach Image to the input of type file using javascript

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?

Upvotes: 0

Views: 3040

Answers (1)

Quentin
Quentin

Reputation: 943571

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.

Upvotes: 2

Related Questions