fix: Compress and retry image upload on 413 error#7435
fix: Compress and retry image upload on 413 error#7435LakshuCodes wants to merge 3 commits intoopenfoodfacts:developfrom
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #7435 +/- ##
==========================================
- Coverage 9.54% 9.10% -0.45%
==========================================
Files 325 625 +300
Lines 16411 36648 +20237
==========================================
+ Hits 1567 3337 +1770
- Misses 14844 33311 +18467 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
monsieurtanuki
left a comment
There was a problem hiding this comment.
Hi @LakshuCodes!
Please have a look at my comments.
Besides, you're copy/pasting code, and it's not appropriate.
A (local) method called twice would be cleaner.
Something like Future<Status> addImage(int compressionPct, bool force).
| // The very same image was already uploaded and therefore was rejected. | ||
| // We just have to select this image, with no angle. |
There was a problem hiding this comment.
Was that so obvious that you felt the urge to remove those comments?
| image, | ||
| uriHelper: uriProductHelper, | ||
| ); | ||
| if (status.status == 'status ok') { |
There was a problem hiding this comment.
Please reuse a const.
| if (status.error?.contains('413') == true || | ||
| status.error?.contains('Request Entity Too Large') == true) { |
There was a problem hiding this comment.
Have you managed to actually get a 413 error?
I assume the server would have directly thrown an exception, with a 413 status code, not a clean "I tried but that's not entirely correct" Status.
To be double-checked.
| cropY1: cropY1, | ||
| cropX2: cropX2, | ||
| cropY2: cropY2, | ||
| compressQuality: 80, // was 100 |
There was a problem hiding this comment.
So that's the only change you make, right? From 100 to 80, forcing the compression.
Could work.
I imagined changing the image dimensions too, but in a first approach you're right.
| uriHelper: uriProductHelper, | ||
| ); | ||
| if (status.status == 'status ok') { | ||
| // successfully uploaded a new picture and set it as field+language |
There was a problem hiding this comment.
Please remove only obvious comments.
|
Hii @monsieurtanuki , the CI checks are failing due to a 401 Unauthorized error at the Set up job step when downloading GitHub Actions (subosito/flutter-action and actions/labeler) |
Fixes #6874
Problem
When uploading a large image (>20MB), the server (nginx) returns a
413 Request Entity Too Large error, causing the upload to fail with
an exception.
Solution
On receiving a 413 error, the app now automatically retries the upload
with a compressed version of the image (80% JPEG quality, forceCompression: true)
using the existing
cropIfNeeded()method.Flow
Changes
packages/smooth_app/lib/background/background_task_image.dartfinal StatustoStatus(mutable)upload()