Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-27108] Android: HTTPClient "responseData" blob returns 0 width/height for images over 512kb

GitHub Issuen/a
TypeBug
PriorityLow
StatusClosed
ResolutionFixed
Resolution Date2019-09-30T14:21:54.000+0000
Affected Version/sn/a
Fix Version/sRelease 8.3.0
ComponentsAndroid
LabelsHTTPClient, android, blob, engSchedule, mimetype
ReporterRodolfo Perottoni
AssigneeJoshua Quick
Created2019-05-28T22:30:59.000+0000
Updated2019-09-30T14:21:54.000+0000

Description

Attachments

FileDateSize
NasaMars.png2019-06-15T00:33:39.000+0000811946

Comments

  1. Abir Mukherjee 2019-06-05

    [~topener], were you able to repro this issue using the test case above? I was not able to repro it. This is my environment: Android 7.0 (Device) and 7.1.1 (Emulator) MacOS 10.14.5 Studio 5.1.2.201903111843 Ti SDK 8.1.0.v20190524093319 Appc NPM 4.2.3 Appc CLI 7.0.12-4 Ti CLI 5.1.1 Node 8.11.4 Java 1.8.0_131 ti.imagefactory 4.0.0 It prints the correct image size both times when I launch the app. EDIT: [~topener] Can you get the URL the user is using for the image? If he is using an image with an unrecognized extension (ie not jpg, png, etc) he might get this issue.
  2. Abir Mukherjee 2019-06-10

    [~rdperottoni] thanks for creating this ticket. I just made my last comment viewable. Can you please provide more information about your environment/settings? I was not able to reproduce it. Does it return the image sizes with SDK 8.0.0/8.0.1?
  3. Abir Mukherjee 2019-06-10

    I was able to reproduce it with the environment I listed in my previous comment. The size is returned correctly when the image extension is png or jpg. When the image extension is .jpeg, it shows 0,0 for the first console.log statement in the test case. The link to the external image I used was: https://upload.wikimedia.org/wikipedia/en/f/f6/Sample_0.JPEG
  4. Joshua Quick 2019-06-15

    It turns out that this issue has nothing to do with the file extension. This issue only happens when downloading an image file is over 512 KB, which is Titanium's max buffer size. This can be reproduced by the "NasaMars.png" image attached to this ticket. A file that exceeds this size will downloaded to a temp file instead of in-memory instead. The reason this bug happens is because Titanium wraps this temp file via a "responseData" blob as it downloads, but will fail to fetch the image width/height initially since the image's header bytes have not been fully downloaded yet. The fix on our end is to re-read the image file's header once the download completes. Note that the max buffer size used by HTTPClient can be changed via the "tiapp.xml" property "ti.android.httpclient.maxbuffersize", but I don't recommend changing it. https://docs.appcelerator.com/platform/latest/#!/guide/tiapp.xml_and_timodule.xml_Reference A simple work-around is to do the following instead. This takes the existing temp file blob (if written to file) and creates a new blob for it when you call the read() method. Note that this does not read all of the bytes in the file. It simply wraps the file reference, making this work-around the better solution from a performance standpoint.
       var imageBlob = httpClient.responseData;
       if (imageBlob.file) {
       	imageBlob = imageBlob.file.read();
       }
       Ti.API.info("@@@ onload() imageBlobSize: " + imageBlob.width + "x" + imageBlob.height);
       
  5. Joshua Quick 2019-06-15

    PR (master): https://github.com/appcelerator/titanium_mobile/pull/10964
  6. Christopher Williams 2019-09-09

    merged to master. No need for "backport" as 8_3_X is going away
  7. Samir Mohammed 2019-09-30

    Closing ticket, fix verified in SDK version 8.3.0.v20190927113609. Test and other information can be found at: https://github.com/appcelerator/titanium_mobile/pull/10964

JSON Source