Repository navigation
fix(pick): carry the size of an image pick - #246
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
Note Kodizm (AI-generated). May contain mistakes; verify before acting. Correct fix, properly awaited at every call site; one coverage gap worth closing before merge. Minor
All six call sites correctly add TestsNew tests cover CI
|
|
Minor ( @kodizm please re-review. |
|
Note Kodizm (AI-generated). May contain mistakes; verify before acting. Coverage gap closed; approving. The only prior finding (missing size assertions for TestsAll six CI
|
What
Pick.image,Pick.images,Pick.camera,Pick.media,Pick.videoandPick.recordVideonow setMagicFile.size, fromXFile.length().Why
The image_picker conversion built every
MagicFilewithout a size, on every platform. A caller guarding an upload limit readsize == nulland let every oversize image through. Found in Uptizm's status page logo upload: on the web a 3 MB PNG skipped the client's 512 KB check, reached PHP's 2 MB ceiling and came back as an unexplained "The logo failed to upload".file_pickerpicks already carry a size (PlatformFile.length()); this brings image picks in line. On the webXFile.length()is the blob's size, so nothing is read into memory.Changes
lib/src/facades/pick.dart:_xFileToMagicFileis async and setssize: await xFile.length(); every call site awaits it (Pick.imagesthroughFuture.wait).test/facades/pick_test.dart:Pick.imageandPick.imagescarry the size, through a fakeImagePickerPlatform.pubspec.yaml:image_picker_platform_interfaceas a dev dependency for that fake.Testing
flutter test: 2360 passed.flutter analyze: no issues.dart format --set-exit-if-changed .: clean.