Skip to content
This repository has been archived by the owner on Apr 12, 2022. It is now read-only.

On Android the url return by getAttachmentUri cannot be download #87

Open
HaydnChen opened this issue Sep 8, 2016 · 5 comments
Open

Comments

@HaydnChen
Copy link

HaydnChen commented Sep 8, 2016

I save a PDF file with content type application/pdf as attachment by saveAttachment api (both tried name with postfix ".pdf" or none postfix) and it success. But when I try to open the uri return by getAttachmentUri in browser or PDF reader or by Linking, it fails on cannot download file. But test that image files such as png and jpg can be download, the PDF file disk size is about 1M.
I wonder whether the REST api flush an attachment http response correctly.

@HaydnChen HaydnChen changed the title The url return by getAttachmentUri cannot be download On Android the url return by getAttachmentUri cannot be download Sep 8, 2016
@npomfret
Copy link
Contributor

npomfret commented Sep 8, 2016

I have it working on android. I don't fully understand your post though. Are you saying that images work but pdfs do not?

What url are you putting into your browser?

@HaydnChen
Copy link
Author

HaydnChen commented Sep 9, 2016

Yes. I start up my app which init CBLite on emulator and get REST url which return by getAttachmentUri from debug console, then open the url in browser to check why view intent failed. When the attachment is image, the url download the image success, but when attachment is PDF browser start to download file but always stop quickly caused by failed to download file though no 404 error occurs. But if I write a react native module method to get attachment content by CBLite database API and write it to android external storage file system the PDF can be open.
So I think upload works but the REST API of get attachment has bug. Maybe should report this issue to couchbase-lite-android.

@npomfret
Copy link
Contributor

npomfret commented Sep 9, 2016

What's the exact url your using?

Are you running on an emulator or physical device? And have you tried the other?

What happens if you drop the attachment name (the bit after the last '/' character) from the url, do you see the underlying document?

Can you send through the underlying document? Its possible the attachment didn't upload correctly which might be clear from the attachment size.

What is the output if you CURL or wget the url? Whats the http status code? 404? 500?

Have you tried on iOS?

@HaydnChen
Copy link
Author

HaydnChen commented Sep 9, 2016

Test that physical device failed also and I've verified that I can get correct PDF input stream by CBLite database api doc.getCurrentRevision().getAttachment(pdfname).getContent() after uploaded. I've not tried IOS, verified that get document REST url works in emulator browser (JSON shows it has attachments of image/png and application/pdf type) and image type attachment REST url works until I upgrade couchbase-lite-android to 1.3.1-30 (1.2.1 still doesn't work), but PDF still failed in 1.3.1-30, so I think the issue is in REST api implementation of couchbase-lite-android.

@HaydnChen
Copy link
Author

To easily reproduce this issue just use Linking.openURL(uri).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants