Image attachment does not work on couchbase lite 1.2.1 android

Hi,

I stored image attachment in couchbase lite, the image url like below as can be directly as html img src:

``http://335804e0-1244-4c57-93b3-916e77c69b0c:3c0eb3d9-3789-4a84-aa36-d03ab99fd9dd@localhost:5984/workout_summary_db/-xpg6Xlg56yfzqGDOBLrU1o/map1447049683401.png

It works fine before I upgraded the phonegap plugin to version 1.2.1, it is just blank there on version 1.2.1, if I switched back to 1.2.0 (no other changes), the cbl attachment image can be displayed correctly.

This might be a regression.

This does sound like a bug. Try doing a GET of the image’s URL in your code and look at what the response status is.

By using Fetch (with option credentials: ‘include’, response status will be 401 without it), GET response are exactly same on both versions:
status: 200
statusText:Ok
ok: true
body: [object ReadableByteStream]

response only has one header, Content-Type: image/png
response content like: �PNG\r\n\u001a\n\u0000\u0000\u0000\rIHDR\u0000\u0000\u0002X\u0000\u0000

I can not find any difference.

both response type is ‘cors’

Sounds like the web view isn’t interpreting the credentials in the URL. See this other thread for more info about similar problems.

It might also have something to do with CORS, but I’m not a web developer and don’t really understand what CORS is.

The cors just mean that request code and the requested resource are not from same server.

Sorry, perhaps I did not make it clear enough. My testing conclusion: even though the request get same result, cbl image can not show up when using cbl cordova plugin 1.2.1, but it can correctly show when using 1.2.0 version, there might be something difference between these two versions, but I can not find clue what to check next.

Thanks for clarifying. This sounds like a different issue than the one I linked to above; I’ve filed a new bug report on Github.

@Hanzhi,

I think the response header is the indicator of what’s wrong. In my app, when I save the image to cblite, I’m specifying the header Content-Type, like “image/jpg”.

I haven’t tried to retrieve the image yet. But you might want to try specifying the Accept-Content-Type header in your request.

You mean Content-Type: image/png? What’s wrong with that?

@jens, sorry I misread @Hanzhi’s posting about Content-Type: image/png.

Is it possibly this bug in android? Basic auth parameters on image urls get ignored because the fresco api doesn’t support 401’s for images.

I’m not sure if the Android REST API supports it (I know iOS doesn’t), but it would solve this problem if you could POST to /_session and get a session cookie that way. Then the API calls wouldn’t have to use basic auth.

I can see the following error log from Android Monitor console:

E/Router: Error 406: Can't satisfy request Accept: image/webp,image/*,*/*;q=0.8

The CBL listener may have trouble interpreting complex Accept: headers like that one. @hideki, do you know?

Since v1.2.1, we added codes to check Accept: header value. However current our code can not handle complex Accept: value.

Workaround: Could you please send Accept: */* or Accept: image/png?

I filed the ticket to couchbase-lite-java-core issue.

@hideki, the web browser is sending the Accept header, so there’s nothing the developer can do.

Hi,

We moved to 1.2.1 a while ago and we had no issue with attachment at all. I understand that this information will not solve the issue you are facing. But maybe helps on its understanding.
Have you checked at the binary level (in hex) that the content you get back from 1.2.0 and 1.2.1 are strictly identicals? It might be an encoding issue…

hope it helps