[image_picker] Handle all images through URI #2728
Conversation
@@ -147,6 +42,7 @@ private static String getPathFromRemoteUri(final Context context, final Uri uri) | |||
String extension = getImageExtension(uri); | |||
inputStream = context.getContentResolver().openInputStream(uri); | |||
file = File.createTempFile("image_picker", extension, context.getCacheDir()); | |||
file.deleteOnExit(); |
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 is a new change to the previous code. I think we really should just try to delete the temp file after the virtual machine exits.
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.
+1 Especially since these files can get large.
Although this would imply the apps should not be storing the File URI anywhere. I don't think we currently recommend that in the documentation. We should fix that.
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.
Good point, will update the doc as well!
assertTrue(path.contains("image_picker")); | ||
assertTrue(path.contains("png")); | ||
assertTrue(path.contains("/cache/")); | ||
} |
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.
you "may" be able to just read from the path and assert that the content are the bytes for the string imageStream too
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.
done
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.
very nice! thanks
Great. Thanks for adding the test. LGTM |
Description
For some historical reason, we have separated the diverged the code to different paths when handling different types of image data. Really, we should always handle the picked image through an URI like what we have been doing for remote images.
This way we can make sure the image picked from URI is definitely usable in the APP.
We don't seem to have a good way to test changes around this code base. I will keep looking into ways to test with JUnit
I have manually tested with downloaded images, images taken from camera, and images from google driver.
Tested with pixel a3 android 11, and some older android builds in emulators.
Related Issues
b/155138680
flutter/flutter#41459
Checklist
Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes (
[x]
). This will ensure a smooth and quick review process.///
).flutter analyze
) does not report any problems on my PR.Breaking Change
Does your PR require plugin users to manually update their apps to accommodate your change?