fresco icon indicating copy to clipboard operation
fresco copied to clipboard

java.lang.IllegalArgumentException: unknown image format

Open ICECHN opened this issue 11 years ago • 12 comments

url="http://ktvme.com//getshareimage.php?id=1528511&s=1"; Fresco load fail, but Glide, Picasso and Volley load success. qq 20150528100334

ICECHN avatar May 28 '15 02:05 ICECHN

I have the same issue with a JPEG file (http://www.titus.de/product-images/details/3D/Skatewachs/Banana_815739.jpg)

And I only found out about it, after wondering why this image is not loaded. So I looked for ways to get log output. I added a RequestLoggingListener and got this output:

06-12 15:10:03.537   5820     6714   unknown:RequestLog..  W  time 967027485: onProducerFinishWithFailure: {requestId: 128, stage: DecodeProducer, elapsedTime: -1 ms, extraMap: null, throwable: java.lang.IllegalArgumentException: unknown image format}
06-12 15:10:03.537   5820     6714   unknown:RequestLog..  W  time 967027486: onRequestFailure: {requestId: 128, elapsedTime: -1 ms, throwable: java.lang.IllegalArgumentException: unknown image format}

Edit: I added an Interceptor via OkHttpClient to log out the response data (without actually parsing the body) and the Response#body().contentType() was null. I tried the same request with Postman (a HTTP request/response tool like curl) and the content type was image/jpeg

2nd Edit: It's the user-agent header. OkHttp's is okhttp/2.3.0 and the server returns a 204:

$ curl -I -L http://www.titus.de/product-images/details/3D/Skatewachs/Banana_815739.jpg -A "okhttp/2.3.0"
HTTP/1.1 204 No Content
Server: nginx
Date: Fri, 12 Jun 2015 15:24:11 GMT
Connection: keep-alive

I tried with different user-agents and the common ones are supported. Even the Google image crawler.

$ curl -I -L http://www.titus.de/product-images/details/3D/Skatewachs/Banana_815739.jpg -A "Googlebot-Image/1.0"
HTTP/1.1 200 OK
Server: nginx
Date: Fri, 12 Jun 2015 15:17:58 GMT
Content-Type: image/jpeg
Content-Length: 28900
Connection: keep-alive
Last-Modified: Sun, 08 Mar 2015 11:40:30 GMT
Cache-Control: max-age=2592000
Expires: Sun, 12 Jul 2015 13:36:26 GMT
X-Cache-Status: HIT

Therefore I think that this (at least my issue) is not directly a Fresco problem. Although I would have liked to see some logs when this happened.

cabbage avatar Jun 12 '15 13:06 cabbage

@cabbage How have you solved that problem? I've added header Request newRequest = chain.request().newBuilder().header("User-Agent", "Googlebot-Image/1.0").addHeader(RestUtils.HEADER, RestUtils.getHashed(finalUrl)) .build(); but it's not working

koptus avatar Aug 28 '15 07:08 koptus

@koptus One way is to get the device's user-agent from the system properties System.getProperty("http.agent")

I know there was an API for this in newer API versions but I'm on vacation and don't have access to the code. You'll have to look this up.

Also, your server must accept the user-agent-string!

cabbage avatar Aug 28 '15 15:08 cabbage

Writing code like this I can see the image without the mentioned problem. Do you have any updates?

Uri uri = Uri.parse("http://www.titus.de/product-images/details/3D/Skatewachs/Banana_815739.jpg");
ImageRequest request = ImageRequestBuilder.newBuilderWithSource(uri).build();
DraweeController controller = Fresco.newDraweeControllerBuilder()
                                          .setImageRequest(request)
                                          .build();
mDraweeView.setController(controller);

massimocarli avatar Oct 14 '15 12:10 massimocarli

By supplying a proper user agent string (not the default okhttp) I had no problem anymore.

Maybe they changed the server settings to allow all user agents. Or maybe there were changes in the library. Maybe it happens only with the okhttp image pipeline.

cabbage avatar Oct 14 '15 16:10 cabbage

@cabbage Thanks for you reply.

massimocarli avatar Oct 14 '15 17:10 massimocarli

Hello, I've got intermittent "java.lang.IllegalArgumentException: unknown image format" for some images. I do not use HttpOK.

Checking apache logs on image server, I found that no request is made by Fresco, thus image is not in disk-cache.

Apache logs : No log or error log for http://domain.tld/imagefolder/image.jpg

Android logs : BufferedDiskCache: Did not find image for http://domain.tld/imagefolder/image.jpg in staging area BufferedDiskCache: Disk cache read forhttp://domain.tld/imagefolder/image.jpg in staging area BufferedDiskCache: Disk cache miss forhttp://domain.tld/imagefolder/image.jpg in staging area SkImageDecoder::Factory returned null BufferedDiskCache: About to write to disk-cache for key for http://domain.tld/imagefolder/image.jpg SkImageDecoder::Factory returned null BufferedDiskCache: Successful disk-cache write for key http://domain.tld/imagefolder/image.jpg AbstractDraweeController: controller 40c00f68 66: final_failed @ onFailure: failure: java.lang.IllegalArgumentException: unknown image format

Error loading 66 java.lang.IllegalArgumentException: unknown image format at com.facebook.imagepipeline.decoder.ImageDecoder.decodeImage(ImageDecoder.java:82) at com.facebook.imagepipeline.producers.DecodeProducer$ProgressiveDecoder.doDecode(DecodeProducer.java:188) at com.facebook.imagepipeline.producers.DecodeProducer$ProgressiveDecoder.access$200(DecodeProducer.java:96) at com.facebook.imagepipeline.producers.DecodeProducer$ProgressiveDecoder$1.run(DecodeProducer.java:128) at com.facebook.imagepipeline.producers.JobScheduler.doJob(JobScheduler.java:207) at com.facebook.imagepipeline.producers.JobScheduler.access$000(JobScheduler.java:27) at com.facebook.imagepipeline.producers.JobScheduler$1.run(JobScheduler.java:78) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581) at com.facebook.imagepipeline.core.PriorityThreadFactory$1.run(PriorityThreadFactory.java:43) at java.lang.Thread.run(Thread.java:1019)

After that first error, "java.lang.IllegalArgumentException: unknown image format " are thrown on every request. Fresco doesn't try to reload on remote server.

AbstractDraweeController: controller 406ae738 67: final_failed @ onFailure: failure: java.lang.IllegalArgumentException: unknown image format Error loading 67 java.lang.IllegalArgumentException: unknown image format at com.facebook.imagepipeline.decoder.ImageDecoder.decodeImage(ImageDecoder.java:82) at com.facebook.imagepipeline.producers.DecodeProducer$ProgressiveDecoder.doDecode(DecodeProducer.java:188) at com.facebook.imagepipeline.producers.DecodeProducer$ProgressiveDecoder.access$200(DecodeProducer.java:96) at com.facebook.imagepipeline.producers.DecodeProducer$ProgressiveDecoder$1.run(DecodeProducer.java:128) at com.facebook.imagepipeline.producers.JobScheduler.doJob(JobScheduler.java:207) at com.facebook.imagepipeline.producers.JobScheduler.access$000(JobScheduler.java:27) at com.facebook.imagepipeline.producers.JobScheduler$1.run(JobScheduler.java:78) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581) at com.facebook.imagepipeline.core.PriorityThreadFactory$1.run(PriorityThreadFactory.java:43) at java.lang.Thread.run(Thread.java:1019)

com.facebook.fresco:fresco:0.8.1 (without+) is used.

Greatings,

Eric

eldk avatar Nov 27 '15 13:11 eldk

The only advice I can give is to check if your request returns correctly. Maybe you use an HTTP proxy/monitor like Charles to find out what response you get from the server. If you get a 204 No Content the server might not accept the user-agent header.

cabbage avatar Nov 27 '15 13:11 cabbage

Hello,

It seems to be a random thing : it's ok for most images. When cache is cleared for testing, the few images that are "not loaded" aren't the same between runs. I've "200" response from apache for image that are correctly loaded and display (apache log). And no log at all for random crashing images.

I check if a request is made or not.

Greatings,

Eric

PS : with 0.7.0+ I haven't had one of those (I will check too).

eldk avatar Nov 27 '15 16:11 eldk

Hello,

I've checked with tcpflow : tcpflow -p -c -i eth0 port 80 | grep -oE '(GET|HEAD) .* HTTP/1.[01]|Host: .*'

I've a GET from my app with Fresco and no log from Apache.

Check the response now.

Eric

eldk avatar Nov 27 '15 16:11 eldk

Hello,

I'm enable to reproduce it for now (nothing changes in the app). I check responses with TCPFLOW and always have 200 answers (and images well loaded). Get back when circumstances will reproduce it (I think this evening) : high load on file server ... ? Greatings, Eric

eldk avatar Dec 02 '15 13:12 eldk

Hello, I have the same issue, I deleted all picture files cached in sdcard path witch I set in fresco,and reload the pictures without any changes in my codes,and it works.So I guess ,if fresco loads image failed uncompletely,when it reloads,it still thow exception the second time,is it a bug?

jianyifu avatar Dec 10 '15 07:12 jianyifu