New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[TIMOB-25849] Android: Always specify image mime-type #9918
Conversation
} | ||
return createDictForImage(imageData, null); | ||
return createDictForImage(imageData, MIME_IMAGE); |
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.
We shouldn't hard code the mime-type like this. This is because the end-user is capable of selecting files others than images from the gallery. I've done it on my devices. In this case, a zero width/height makes sense.
Have a look at how my open PR handles it here...
https://github.com/appcelerator/titanium_mobile/pull/9223/files-diff
Here is a code snipped from my PR. It'll fetch the mime-type from the gallery app's content provider using the given content URI. I've tested this with photos, videos, and text files and it works. And I think it's okay to leave it null
if the selected file is unknown since that won't happen for photos.
// Determine the mime type for the given file.
String mimeType = null;
boolean isPhoto = false;
try {
mimeType = TiApplication.getInstance().getContentResolver().getType(Uri.parse(path));
if ((mimeType != null) && mimeType.toLowerCase().startsWith("image")) {
isPhoto = true;
}
} catch (Exception ex) {
}
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.
Also note that the above will correctly set the mime-type for the selected image format such as "image/png", "image/jpeg", etc.
@jquick-axway Updated PR, we now attempt to obtain the mime-type from the content resolver. Also note that the user should not be able to select anything other than images due to this filter; although that may not be enforced correctly on all devices. |
Generated by 🚫 dangerJS |
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.
CR: Pass
FR Passed.
Studio Ver: 5.0.0.201712081732 |
TiBlob
NOTE:
no tests
as this test case requires user inputTEST CASE
width height
andmimeType
populated after selecting an imageJIRA Ticket