upload endpoint #5

Merged
w2 merged 14 commits from w2/photovoter_backend:upload into main 4 years ago
w2 commented 4 years ago
Owner

/upload_pictures

Новый эндпоинт для загрузки фотографий.

Потребляет zip архивы с фотографиями, внутренняя структура директорий свободная.

Загрузка архива возвращает 202 "Accepted" статус и передаёт его на обработку отдельной функции. Возможна одновременная обработка нескольких архивов.

Загрузка недопустимого архива возвращает 415 "Unsupported Media Type".

Загрузка ограничена сочетанием имени пользователя и пароля, конфигурируемым в config.py; неверные сочетания возвращают 401 "Unauthorized"

# /upload_pictures Новый эндпоинт для загрузки фотографий. Потребляет zip архивы с фотографиями, внутренняя структура директорий свободная. Загрузка архива возвращает 202 "Accepted" статус и передаёт его на обработку отдельной функции. Возможна одновременная обработка нескольких архивов. Загрузка недопустимого архива возвращает 415 "Unsupported Media Type". Загрузка ограничена сочетанием имени пользователя и пароля, конфигурируемым в config.py; неверные сочетания возвращают 401 "Unauthorized"
w2 added 10 commits 4 years ago
Poster
Owner

fixes #2

fixes #2
w2 changed title from upload to upload endpoint 4 years ago
g requested changes 4 years ago
main.py Outdated
tasks.add_task(
unpack_pictures_zip,
file=file,
time=datetime.utcnow().replace(microsecond=0).isoformat(),
g commented 4 years ago
Owner

Windows doesn't support colons in path. Use time.time()

Windows doesn't support colons in path. Use `time.time()`
"OriginalImage": path.join(DEST_ORIGINAL, filename),
"ResizedImage": path.join(dest_shrunk, filename),
"OriginalImage": path.join(dest_original, filename),
"DateTimeOriginal": exif["DateTimeOriginal"], # Q: normalize it?
g commented 4 years ago
Owner

Ignore invalid images (no required exif data)

Ignore invalid images (no required exif data)
g commented 4 years ago
Owner

Протестировал на фотках с координатами. Всё работает. Для тестирования тут https://transfer.sh/W4P8gz/IMG_8403.zip

Протестировал на фотках с координатами. Всё работает. Для тестирования тут https://transfer.sh/W4P8gz/IMG_8403.zip
w2 force-pushed upload from f5f04cde08 to 3e7ef81102 4 years ago
w2 requested review from g 4 years ago
g requested changes 4 years ago
g left a comment
Owner

It works fine. Only major issue is image flipping which is probably connected to this row. Coordinates recalculation would improve usability too.

It works fine. Only major issue is image flipping which is probably connected to [this row](https://git.iamonlyherefortheicecream.ml/DIWHY/photovoter_backend/pulls/5/files#issuecomment-26). [Coordinates recalculation](https://git.iamonlyherefortheicecream.ml/DIWHY/photovoter_backend/pulls/5/files#issuecomment-27) would improve usability too.
"testbox/photovoter.dblite" # Q: any allowances for this being not OUR database?
)
DATA_LOCATION = "/tmp/123"
g commented 4 years ago
Owner

Add comment that DATA_LOCATION should end with a slash like test/. Else in Windows a path stored in a database looks like this test\image/img.jpg. It could cause problems in a frontend.

Add comment that `DATA_LOCATION` should end with a slash like `test/`. Else in Windows a path stored in a database looks like this `test\image/img.jpg`. It could cause problems in a frontend.
Poster
Owner

Better yet, we can just normalize it. Can be done right in the config.py (since we made it .py) but it's only used in a handful of places so let's not clutter it with code just yet.

Better yet, we can just normalize it. Can be done right in the config.py (since we made it *.py*) but it's only used in a handful of places so let's not clutter it with code just yet.
Poster
Owner

Fixed now.
Some say Python on Windows will automatically handle forward slashes (/) properly.
You probably shouldn't mix and match DBs from different systems, tho. So, if upload to windows, serve from windows too.

Fixed now. Some say [Python on Windows will automatically handle forward slashes (/) properly](https://stackoverflow.com/questions/19065115/python-windows-path-slash#comment28179188_19065182). You probably shouldn't mix and match DBs from different systems, tho. So, if upload to windows, serve from windows too.
"ResizedImage": path.join(DEST_SHRUNK, filename),
"OriginalImage": path.join(DEST_ORIGINAL, filename),
"DateTimeOriginal": exif["DateTimeOriginal"], # Q: normalize it?
"GPSLatitude": exif["GPSLatitude"],
g commented 4 years ago
Owner

Could we transform it to decimal form? See https://gis.stackexchange.com/questions/136925/how-to-parse-exif-gps-information-to-lat-lng-decimal-numbers
Now it looks like this
image

To convert it we should dec_degree = 55 / 1 + 40 / 1 / 60 + 515 / 100 / 3600 = 55.66810 (five decimal places are enough). General formula is dec_degree = degreesNumerator / degreesDenominator + minutesNumerator / minutesDenominator / 60 + secondsNumerator / secondsDenominator / 3600.

Could we transform it to decimal form? See https://gis.stackexchange.com/questions/136925/how-to-parse-exif-gps-information-to-lat-lng-decimal-numbers Now it looks like this ![image](https://i.ibb.co/gjpDzT0/image.png) To convert it we should `dec_degree = 55 / 1 + 40 / 1 / 60 + 515 / 100 / 3600 = 55.66810` (five decimal places are enough). General formula is `dec_degree = degreesNumerator / degreesDenominator + minutesNumerator / minutesDenominator / 60 + secondsNumerator / secondsDenominator / 3600`.
Poster
Owner

Independent of this PR. (Should have done in in #4). I filed #7.

Independent of this PR. (Should have done in in #4). I filed #7.
cloned.strip() # Q: may damage icc, do we allow that or use smh else?
cloned.transform(resize="50%") # Q: what do we want here?
g commented 4 years ago
Owner

I think width=1000px with preserved aspect ratio would be enough.

I think width=1000px with preserved aspect ratio would be enough.
Poster
Owner

Independent of this PR. I filed #8.

Independent of this PR. I filed #8.
Poster
Owner

Only major issue is image flipping which is probably connected to this row.

Independent of this PR, i filed #9

> Only major issue is image flipping which is probably connected to this row. Independent of this PR, i filed #9
w2 added 1 commit 4 years ago
w2 requested review from g 4 years ago
g approved these changes 4 years ago
g left a comment
Owner

Looks good to me 👍

Looks good to me 👍
w2 merged commit 2f967b584f into main 4 years ago
w2 deleted branch upload 4 years ago

Reviewers

g approved these changes 4 years ago
The pull request has been merged as 2f967b584f.
Sign in to join this conversation.
No reviewers
No Label
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date

No due date set.

Dependencies

No dependencies set.

Reference: DIWHY/photovoter_backend#5
Loading…
There is no content yet.