Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

[image_picker] Fixes an issue where videos could be wrongly picked with .jpg extension #2860

Closed
wants to merge 1 commit into from

Conversation

miguelpruivo
Copy link

@miguelpruivo miguelpruivo commented Jul 3, 2020

Fixes an issue where videos could be wrongly picked with .jpg extension.

Description

When picking videos on Android devices, it will return file names ended with .jpg extension, regardless of the file being actually a video. This requires a workaround implementation, such as opening a File descriptor on Flutter side and rename it to .mp4 again.

The issue happens because some URI paths doesn't have an extension and it was being extracted just by splitting the file name from . and getting the last part, which make it not quite reliable for some scenarios. Right now, I've updated the source to retrieve the extension based on the URI content.

As a note, this doesn't happen with all Android devices, but I can see it easily replicable with Samsung phones.

Related Issues

Fixes #52419

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.

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • My PR includes unit or integration tests for all changed/updated/fixed behaviors (See Contributor Guide).
  • All existing and new tests are passing.
  • I updated/added relevant documentation (doc comments with ///).
  • The analyzer (flutter analyze) does not report any problems on my PR.
  • I read and followed the Flutter Style Guide.
  • The title of the PR starts with the name of the plugin surrounded by square brackets, e.g. [shared_preferences]
  • I updated pubspec.yaml with an appropriate new version according to the pub versioning philosophy.
  • I updated CHANGELOG.md to add a description of the change.
  • I signed the CLA.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Does your PR require plugin users to manually update their apps to accommodate your change?

  • Yes, this is a breaking change (please indicate a breaking change in CHANGELOG.md and increment major revision).
  • No, this is not a breaking change.

@miguelpruivo miguelpruivo force-pushed the master branch 2 times, most recently from a8b3edb to 9cac534 Compare July 17, 2020 14:16
@miguelpruivo
Copy link
Author

This has been approved by all reviewers. If it could be merged it would be great to prevent constant rebasing 😄

Thanks!

@agavrel
Copy link

agavrel commented Aug 1, 2020

Could this PR be approved? Many thanks in advance

@abner-hello-world
Copy link

I need this fix, and I have this problemI hope the author will update soon. Thank you

@venkatd
Copy link

venkatd commented Aug 5, 2020

I can confirm that running off the fork resolves the issue for me

My pubspec.yaml declaration

  image_picker:
    git:
      url: https://github.com/miguelpruivo/plugins
      ref: 9cac5347d9ab9d111a918a8154fb060565b1bf31
      path: packages/image_picker/image_picker

@abner-hello-world
Copy link

abner-hello-world commented Aug 6, 2020 via email

@SivaramNalliboyana
Copy link

I can confirm that running off the fork resolves the issue for me

My pubspec.yaml declaration

  image_picker:
    git:
      url: https://github.com/miguelpruivo/plugins
      ref: 9cac5347d9ab9d111a918a8154fb060565b1bf31
      path: packages/image_picker/image_picker

I tried the way, but still it is giving me a .jpg

@pedromassango
Copy link
Member

@miguelpruivo You may want to add Fixes before the issue id so that it automatically closes the issue when merged.

@miguelpruivo
Copy link
Author

@pedromassango done! 🎉

@pingbird
Copy link
Member

Hi, @danielwalczak @awazgyawali @fdcgr

Thanks for your reviews!

As per our tree hygiene https://github.com/flutter/flutter/wiki/Tree-hygiene#how-to-review-code we avoid people without commit access to this repo approving changes during a review as this confuses authors into thinking the PR is ready to merge. (Regular reviews are much appreciated, just don't click the approve changes button)

@miguelpruivo

Very sorry for such a long wait 😢

I would love to merge this however due to the lack of unit tests and my lack of experience here are some questions:

  1. Why does this happen? Does this only apply to videos not saved with a file extension?
  2. How hard would it be to add tests?
  3. How does this behavior differ from iOS?
  4. This fix seems to replace the extension detection logic entirely rather than using it as a fallback. If the uri does have an extension will this still use that extension verbatim? I'm specifically looking for any notable changes in behavior outside of files given .jpg.

I trust that it works because you have done this sort of thing before but we still need to make sure this doesn't break anything on a patch release version. (love your work on file_picker btw)

@ditman
Copy link
Member

ditman commented Sep 16, 2020

@miguelpruivo, @PixelToast I found another approach to do this here: #2821, do you think this is something that can be collaborated upon, so we only have to merge one PR to fix two bugs?

@pedromassango
Copy link
Member

I agree that the fix for image extension issue is better handled here than on #2821. Maybe collaborate is the better idea to merge just one PR.

@miguelpruivo
Copy link
Author

@PixelToast hi, thank you for the input.

Currently I’m off on vacations until next week. However, I’ll try to help you as much as I can.

  • Apparently this happens because the uri is treated as an image and not a video;
  • Unit tests are not actually the easiest for native pickers as you’ll have to fully drive the picking behavior (integration test) and handle its results;
  • This only affects Android, on iOS the plugin implementation is behaving properly;

Let me know if you need anything else.

@ened
Copy link
Contributor

ened commented Sep 16, 2020

@PixelToast @miguelpruivo @pedromassango

Hi! I prefer to have two PRs, one for the image resizing (GIF) and one for the correct/incorrect JPG extension handling.

@ditman Let's get this PR ready for merge first and I can rebase #2821 after that.

@ditman
Copy link
Member

ditman commented Sep 16, 2020

@ened sounds good to me!

@pingbird
Copy link
Member

@miguelpruivo Thanks for the update, it's good to know you are still able to help.

If full integration tests aren't feasible, just a unit test for getImageExtension should be fine.

@miguelpruivo
Copy link
Author

miguelpruivo commented Sep 17, 2020

@PixelToast ok no problem. I’ll try to get it done as soon as I return home at the weekend.

@nicemanis
Copy link

Tested with:

image_picker:
  git:
    url: https://github.com/miguelpruivo/plugins
    ref: 9cac5347d9ab9d111a918a8154fb060565b1bf31
    path: packages/image_picker/image_picker

Videos are selected correctly with .mp4 extension. The picked file playback also works as expected.

@miguelpruivo
Copy link
Author

miguelpruivo commented Oct 20, 2020

Done @pedromassango.

Copy link

@jpetro416 jpetro416 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correctly fixes extension issue

@pedromassango
Copy link
Member

This seems ready for review.

Cc @cyanglaz

@frankyvij
Copy link

Can this be reviewed and merged, it has been 5 days already.

@miguelpruivo
Copy link
Author

@frankyvij it has been 3 months, actually. 😅

Copy link
Contributor

@cyanglaz cyanglaz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! This is great. We will need to add tests before we can land this.

@syssam
Copy link

syssam commented Nov 2, 2020

any update for this pr? thanks

@tegarkurniawan
Copy link

any update ?

Copy link

@do4Mother do4Mother left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i test it using latest stable flutter version. and its works fine

@thegrxp
Copy link

thegrxp commented Dec 2, 2020

Any reason why it's not merged yet?

@fluttergithubbot
Copy link

This pull request is not suitable for automatic merging in its current state.

  • The status or check suite publishable has failed. Please fix the issues identified (or deflake) before re-applying this label.
  • The status or check suite format has failed. Please fix the issues identified (or deflake) before re-applying this label.
  • The status or check suite test has failed. Please fix the issues identified (or deflake) before re-applying this label.
  • The status or check suite analyze has failed. Please fix the issues identified (or deflake) before re-applying this label.
  • The status or check suite build_all_plugins_apk has failed. Please fix the issues identified (or deflake) before re-applying this label.
  • The status or check suite integration_web_smoke_test has failed. Please fix the issues identified (or deflake) before re-applying this label.
  • The status or check suite build-apks+java-test+firebase-test-lab has failed. Please fix the issues identified (or deflake) before re-applying this label.
  • The status or check suite build-linux+drive-examples has failed. Please fix the issues identified (or deflake) before re-applying this label.
  • The status or check suite build_all_plugins_ipa has failed. Please fix the issues identified (or deflake) before re-applying this label.
  • The status or check suite lint_darwin_plugins has failed. Please fix the issues identified (or deflake) before re-applying this label.
  • The status or check suite build-ipas+drive-examples has failed. Please fix the issues identified (or deflake) before re-applying this label.
  • The status or check suite build_all_plugins_app has failed. Please fix the issues identified (or deflake) before re-applying this label.
  • The status or check suite build-apps+drive-examples has failed. Please fix the issues identified (or deflake) before re-applying this label.
  • The status or check suite Prebuild .ci/Dockerfile has failed. Please fix the issues identified (or deflake) before re-applying this label.
  • The status or check suite Prebuild .ci/Dockerfile-LinuxDesktop has failed. Please fix the issues identified (or deflake) before re-applying this label.

@eugrro
Copy link

eugrro commented Dec 19, 2020

Can this be merged in? This seems to be a problem that has existed for a while

@pedromassangocode
Copy link

@miguelpruivo do you still have plans to work on this? It seems that this PR only need tests as mentioned in #2860 (comment).

@miguelpruivo
Copy link
Author

@pedromassango I'm sorry but currently I'm out of time to work on that. I might implement it but with no ETA.

@danielroek
Copy link
Contributor

I created a PR with a working Unit Test. #3685

@cyanglaz
Copy link
Contributor

cyanglaz commented Mar 9, 2021

closing this in favor of #3685 as that one has tests.
We are going to try to land #3685 asap

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[image_picker] image_picker returns .jpg extension when picking Video or GIF