N
N
NikitoZ Sc.2015-10-22 09:16:09
JavaScript
NikitoZ Sc., 2015-10-22 09:16:09

How to push photo from user's webcam into input[type="file"]?

I carefully lit up the documentation on getUserMedia () and getting a picture from the user's camera in canvas. There was one question left: how to assign this received photo as a "value" for the input field?
Now there is one large form, with a bunch of fields, including file attachments. Everything is sent to the server in bulk. There is an irresistible desire to attach files directly from the webcam. The preview window with the stream and getting a snapshot is almost completed. Only this moment slows down :(

Answer the question

In order to leave comments, you need to log in

3 answer(s)
I
Ivan, 2015-10-22
@Niki-Z

Nothing can be stuffed into input[type=file] . As an option canvas.asDataURL and forward this value in a hidden field. To some extent, crutches, but nothing faster comes to mind

I
Ilya Beloborodov, 2015-10-22
@kowap

Why do you need input[type=file]?
I would do so.
The user enters a page, for example, filling out his profile, where, in addition to his name, date of birth, etc., you need to connect through a webcam.
To do this, when entering the page, you need to create a ramdom identifier, save it to the session. After the user has taken a photo, the path to the photo is written to the database along with this identifier, which he has in the session. When a person saves the profile (name, surname, birthday, etc.), then together with the profile we save this very identifier, after saving the profile, we look for a photo by this identifier and associate it with the profile

A
Artem Zelenskiy, 2017-12-07
@artzelenskiy

Good day. I'm typing the registration page and a similar question arose with yours. May I know how you solved it?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question