Connecting photos from phone with form data in django db

I am attempting to have my web app allow photos from users, when on a phone, and put into db. Scenario: User is on a form page and clicks “take picture” button on form and device takes pic and it gets tied to other data on a form submission. I understand the actual picture taking is HTML5/JS/CSS but I do not yet know how to name the images so multiple different users/photographers image names do not collide and how to get them into the db with semantic names. What I did find is that each APP phones use to take photos seem to have their own naming convention, suggesting this can be set.

I already have the capability to upload images from local device into db. That is done. But taking photo on phone and connecting them to other form data on same page is baffling me.

This has to be a fairly common issue but I have found nothing to help yet and have only thought of convoluted solutions that are beyond my skill level (newb). Is there any middleware? Examples? Do you have any thoughts on how to do this?

Many thanks.

When you handle the form submission containing the image, you have the ability in your view to assign any file name you wish. (You could then add an additional field for the submitted file name to save / user for reference later.)

I’ve never tried to do what you’re looking for, so I don’t have any specific assistance I can provide. But, what you might do is some “exploratory debugging” on the web side. If you know how to use a debugger to watch your code, you could set a break point at the beginning of your view to see exactly what was submitted by the form.
Otherwise, you could add some print statements in your view to (non-interactively) see what is received by the submission. (See the File Uploads docs to get some ideas of what you might see.)


THANKS! I did not know I could modify the file name. That is half of it I bet… I could prefix some alphanumeric and random number to ensure no name collision.

OK, I am off to read then…

Thanks for being out there in the ether!

What we do for our file uploads is completely generate a file name, primarily just a serial number. All the other data associated with that file, the original file name, current file name (editable by the user), date/time it was uploaded, mime type, and size, are stored in an ancillary table.