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

Conversation

@AmolGangadhare
Copy link
Contributor

@AmolGangadhare AmolGangadhare commented Jul 5, 2019

Removed cursor and added MimeTypeMap.getFileExtensionFromUrl to prevent crash occurring in some scenarios.

Description

App is crashing in some scenarios while image picked from the file manager or other sources. In a line:182 while getting the mimeType for an image it was causing the app to crash as sometimes there is no mime type available for the image. Now, to get image extension cursor is removed and now extension will be taken from MimeTypeMap.getFileExtensionFromUrl

Related Issues

Fixes flutter/flutter#35632

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.

Removed cursor and added MimeTypeMap.getFileExtensionFromUrl to prevent crash occurring in some scenarios.
Code formatted (flutter_plugin_tools)
upgraded gradle version

dependencies {
classpath 'com.android.tools.build:gradle:3.3.0'
classpath 'com.android.tools.build:gradle:3.4.1'
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems not related to this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

gradle was updated after the PR made, it would be better if added with this PR else not necessary.

Copy link
Contributor

Choose a reason for hiding this comment

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

ok, it'd be nice to rebase the PR so we won't see this diff here

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry i misunderstood your comment here. I think what I wanted to say is that let's remove change in this particular PR, since it is not related to the PR. Also please remove the related bit in the CHANGELOG

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok, I'll remove gradle change and comment from the changelog.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@cyanglaz I've restored the gradle version and updated changelog.

if (cursor != null) {
cursor.close();
}
extension = MimeTypeMap.getFileExtensionFromUrl(uriImage.getPath());
Copy link
Contributor

Choose a reason for hiding this comment

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

I did some research on this method and I found this: https://stackoverflow.com/questions/14320527/android-should-i-use-mimetypemap-getfileextensionfromurl-bugs/14321470
it seems getFileExtensionFromUrl is not sufficient for all scenarios?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

agreed, would be better to find the extension manually but in some scenarios, I found that file uri doesn't have an extension so in that case, it will also not sufficient. so checking for null or empty extension and applying manual extension will be working.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sure, do you mind to add code to manually check the extension as well?
Something like

extension = fromURI
if (extension == null) {
  extension = manuallyParsing
}
if (extension == null) {
  extension = ".jpg" (i believe this is already handled)
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

did the change, null check for extension was already there, in addition to that I added an empty check to prevent rare scenarios.

Removed MimeTypeMap.getFileExtensionFromUrl. Now extension will be retrieved manually.
@cyanglaz
Copy link
Contributor

cyanglaz commented Jul 8, 2019

LGTM! Please update the pubspec and changelog with the a new version, please also fix the formatting.

Code formmated. Pubspec and Changelog is updated
Restored gradle version and updated changelog
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.

LGTM!

@cyanglaz cyanglaz merged commit 36b9fc8 into flutter:master Jul 9, 2019
mithun-mondal pushed a commit to bKash-developer/archived_plugins that referenced this pull request Aug 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[image_picker] Plugin crash while picking image

3 participants