-
-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Upload ODK submission user photos to S3 for easy access #1744
Conversation
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
β¦ feat/upload-image-to-s3
for idx, filename in enumerate(attachments): | ||
s3_key = f"{s3_base_path}/{instance_id}/{idx+1}.jpeg" | ||
|
||
if object_exists(s3_bucket, s3_key): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will make a lot of calls to S3 potentially!
Not a problem with Minio, but slow if external S3.
Could we do a comparison for what the submission says should exist against the database table instead?
We would need the stat
approach if we didn't gave the db table π
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah makes sense! π€
|
||
# Insert the record into submission_photos table | ||
sql = text(""" | ||
INSERT INTO submission_photos ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also this could be batched for efficiency.
It's generally good to not make db queries in a for loop - instead gather the data (images uploaded) there in a dict or something, then do a batch db table insert in one go π
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
okay
-- Start a transaction | ||
BEGIN; | ||
|
||
CREATE TABLE submission_photos ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check this SQL doesn't error if you run it twice π
Maybe create table if not exists
will fix
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
okay
|
for more information, see https://pre-commit.ci
Looks good! Merging π« |
What type of PR is this? (check all applicable)
Related Issue
- Extract user photos from submissions and make available via S3Β #1701
- Add a database record of photos taken in the fieldΒ #1729
Describe this PR
This PR creates a function to upload submission images to s3
submission_photos
table with fieldsproject_id
,task_id
,submission_id
, ands3_path
Screenshots
N/A
Alternative Approaches Considered
Did you attempt any other approaches that are not documented in code?
Review Guide
Checklist before requesting a review
[optional] What gif best describes this PR or how it makes you feel?