I want to enable image (& audio & video) uploads in a survey framework. To do so, input file is nearly sufficient for my purposes.
On some mobile browsers <input type="file" accept="image/*;capture=camera">
is a really
simple way of letting users choose to upload an existing image or to
take a new one. Of course the UI for viewing and choosing among the pictures
is provided too.
Desktop browsers did not go this route. Instead, some pretty nice stuff seems
to be possible using getUserMedia()
.
I did not find any working examples that upload the collected user-media to the server (e.g. I found https://github.com/codepo8/interaction-cam/ via this answer. It shows video, but doesn't capture in my Firefox and isn't "aware" of it either, it doesn't show video at all in Safari). I'm not sure how much of this is hardware-specific (my Macbook Air's camera has been on/off-broken in Chrome for a long time now).
Is there some sort of polyfill for uploading captured images that can fall back to a simple file input in case of trouble/access denial?
I've since found getUserMedia.js, which works in Firefox. It falls back to Flash, which is nice, I'll have to see if I am able to tweak it to fall back to input type="file" in mobile browsers.
On desktop, to access the webcam:
navigator.getUserMedia
ORnavigator.mediaDevices.getUserMedia
Once access is granted, to record the webcam:
PS: on mobile the HTML Media Capture spec has evolved, accept="image/*;capture=camera"
never made it to the W3C Candidate Recommendation. Use just accept="image/*"
instead and separately add capture="capture"
(Boolean) only if you want to force capture from the camera. See Correct Syntax for HTML Media Capture for more details.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With