I have a rails app with a sign-up page, where users fill in a form with their details. I want to add a field for user's picture: rather than uploading it, I want the user to take a picture using their webcam. The picture is supposed to be saved to the disk and the DB to be updated with its name and path.
How can I do this? I know that the storage was previously handled by paperclip but it is nowadays done using Active Storage, but what about using the webcam? googling "ruby gem webcam" and limiting results to the last year has been surprisingly unhelpful, with most results being porn-related.
If you want to use the webcam then you'll need to handle that side of things in JavaScript. You would need to use the getUserMedia API to get access to the camera stream. Once you've got that, you can capture a still by writing frames from the camera into a canvas, then exporting the canvas to an image with Canvas.toDataBlob.
Some browsers expose more access to the camera for capturing images, but you'll still get a blob eventually.
Once you've got that, you can add it to a FormData object and submit to your Rails app at which point Active Storage can take over storing the file.