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-17567] Android: Replace the use of getFileExtensionFromUrl as it is for enco... #6216
Conversation
…ncoded url and have issues with path with special characters
Sunil, I'm not seeing any test case in the ticket for this fix. Can you update the test case please? |
test case added |
I'm still getting "[INFO] : 0 . 0 . application/octet-stream" from
Line 228 of the TiBlob, when it loads the BitmapInfo including the width and height, it actually doesn't do that cause the mimetype is "application". changing it to:
Made it work for me. |
I didn't understand the comment. Why should we process mimetype 'application/' as image? what is the image filename you used? |
I used the attached zipfile "MapModule.zip" along with the "salachi:TIMOB-17567" Branch. Image was "Earth.jpg". As mentioned in the ticket, using the line of code on android:
Produces:
The bitmap information of height an width is not loaded as the mime type as shown in the logs is "application" and not "image". This causes the "loadBitmapInfo()" method not load the height and width resulting in the case in the logs for android. |
And I think you are right. We should only process "image". I'm trying to see why in my case I'm getting the Mime type as "application" instead. |
I found the problem here. https://github.com/appcelerator/titanium_mobile/blob/58198c641d77e17d156431666e80bae732b5c130/android/titanium/src/java/org/appcelerator/titanium/TiBlob.java#L208 Android's implementation of "URLConnection.guessContentTypeFromStream(is)" is limited. It doesn't detect JPEG. From the source code: https://android.googlesource.com/platform/libcore/+/master/luni/src/main/java/java/net/URLConnection.java from line 695 onwards, you can see that the guess method is really really limited. It doesn't detect "image/jpeg" at all. Thus, because of that, our code returns, null and defaults to "application/octet". We need to handle the inputstream ourselves to detect JPEG in our "guessContentTypeFromStream()" method. We can do it by doing something similar to this http://www.cnblogs.com/unixmaomao/archive/2012/12/03/2800143.html Here's also more list of mimetypes and their binary bytes used to identify them that we could consider detecting: http://book.javanb.com/java-network-programming-3rd/javanp3-CHP-15-SECT-10.html |
I tried with a jpg file and it is working fine. Here is what I tried mtm.getMimeTypeFromExtension is returning the right mime type. |
Ah I see.. I did it with:
|
Doing it using your method did indeed produce: Which is correct. I think the problem comes when using Ti.Stream.pump and the loadBitmapInfo() method is used as I mentioned earlier. Could you try running my sample code and see if you can get the same "0 . 0 . application/octet-stream" as me? |
Ashraf, you are right, there is another bug in getting mimetype from stream. Fix submitted |
Code reviewed and functionally tested. It's working correctly. :) |
Code reviewed. Looks good |
[TIMOB-17567] Android: Replace the use of getFileExtensionFromUrl as it is for enco...
https://jira.appcelerator.org/browse/TIMOB-17567
Replace the use of getFileExtensionFromUrl as it is for encoded url and won't work with path with special characters.