CBL Android: Cannot push attachments over 16KB

202 views
Skip to first unread message

jvatt

unread,
Jun 26, 2014, 11:04:44 AM6/26/14
to mobile-c...@googlegroups.com
I have a simple android program which has a push and pull replication running continuous on a CouchDB database in a local server. 

When saving a new revision with an attachment that's size is over 16 KB, I get java.io.IOException: read failed: EBADF (Bad file number). 
The document gets pushed to the database, but without the attachment. Attachments under 16 KB's get pushed just fine.

In couchbase-lite-java-core/Database.java is the following line: public static int kBigAttachmentLength = (16*1024);
Probably just a coincidence, though.

Code:
        Document document = m_database.createDocument();

        // save the ID of the new document
        String docID = document.getId();

        // retrieve the document from the database
        Document retrievedDocument = m_database.getDocument(docID);
        Map<String, Object> properties = new HashMap<String, Object>();
        properties.put("cbltest", "testNote");
        
        try{
        retrievedDocument.putProperties(properties);
        }
        catch(Exception e)
        {
        e.printStackTrace();
        }
        
        UnsavedRevision newRevision = m_database.getDocument(docID).createRevision();

        AssetManager am = getAssets();
        InputStream is;
        try {
            is = am.open(filename);
        }
        catch(IOException e)
        {
            Log.e(TAG, "Unable to open " + filename);
            return;
        }

        newRevision.setAttachment(filename, "application/octet-stream", is);
        try {
            newRevision.save();
        }
        catch (CouchbaseLiteException e)
        {
            Log.d("TAG", "Cannot save attachment", e);
        }


Stacktrace:

Exception uploading multipart request
java.io.IOException: read failed: EBADF (Bad file number)
  at libcore.io.IoBridge.read(IoBridge.java:442)
  at java.io.FileInputStream.read(FileInputStream.java:179)
  at java.io.InputStream.read(InputStream.java:163)
  at org.apache.http.entity.mime.content.InputStreamBody.writeTo(InputStreamBody.java:87)
  at org.apache.http.entity.mime.HttpMultipart.doWriteTo(HttpMultipart.java:206)
  at org.apache.http.entity.mime.HttpMultipart.writeTo(HttpMultipart.java:224)
  at org.apache.http.entity.mime.MultipartEntity.writeTo(MultipartEntity.java:183)
at org.apache.http.impl.entity.EntitySerializer.serialize(EntitySerializer.java:97)
  at org.apache.http.impl.AbstractHttpClientConnection.sendRequestEntity(AbstractHttpClientConnection.java:162)
  at org.apache.http.impl.conn.AbstractClientConnAdapter.sendRequestEntity(AbstractClientConnAdapter.java:272)
  at org.apache.http.protocol.HttpRequestExecutor.doSendRequest(HttpRequestExecutor.java:237)
  at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:119)
  at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:428)
  at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
  at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
  at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
  at com.couchbase.lite.support.RemoteRequest.executeRequest(RemoteRequest.java:208)
  at com.couchbase.lite.support.RemoteMultipartRequest.run(RemoteMultipartRequest.java:49)
  at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:442)
  at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
  at java.util.concurrent.FutureTask.run(FutureTask.java:137)
  at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:150)
  at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:264)
  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
  at java.lang.Thread.run(Thread.java:856)
 Caused by: libcore.io.ErrnoException: read failed: EBADF (Bad file number)
  at libcore.io.Posix.readBytes(Native Method)
  at libcore.io.Posix.read(Posix.java:118)
  at libcore.io.BlockGuardOs.read(BlockGuardOs.java:149)
  at libcore.io.IoBridge.read(IoBridge.java:432)



Traun Leyden

unread,
Jun 26, 2014, 12:55:31 PM6/26/14
to mobile-c...@googlegroups.com
I don't think that's a coincidence, I think CBL Android is not sending the multipart request in the way CouchDB expects it.

Are you using the master branch?

The 1.0 version still has this issue with CouchDB attachments:


I'm assuming issue #214 fixed attachment issues for any size attachment, but if you are using a version with the fix, then we'll need to open a bug.



--
You received this message because you are subscribed to the Google Groups "Couchbase Mobile" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mobile-couchba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mobile-couchbase/115f28a8-03e1-421f-9f43-3afbd84470f3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

jvatt

unread,
Jun 27, 2014, 3:51:22 AM6/27/14
to mobile-c...@googlegroups.com

Traun Leyden

unread,
Jun 30, 2014, 2:19:25 PM6/30/14
to mobile-c...@googlegroups.com

That sounds like a bug then.  Can you file a ticket here? https://github.com/couchbase/couchbase-lite-java-core


Traun Leyden

unread,
Jun 30, 2014, 9:20:12 PM6/30/14
to mobile-c...@googlegroups.com

jvatt

unread,
Jul 1, 2014, 6:52:29 AM7/1/14
to mobile-c...@googlegroups.com
Nice. Thank you!

Traun Leyden

unread,
Jul 1, 2014, 12:34:34 PM7/1/14
to mobile-c...@googlegroups.com

It should be fixed now, please check http://factory.couchbase.com/view/build/view/mobile_dev/view/android/view/master/job/build_cblite_android_master/ for the next build.  (412)

If there's a build failure, you can open a github issue for it.

jvatt

unread,
Jul 2, 2014, 3:29:37 AM7/2/14
to mobile-c...@googlegroups.com
I'm still getting the error on build 412.

Traun Leyden

unread,
Jul 2, 2014, 11:17:33 AM7/2/14
to mobile-c...@googlegroups.com
Yeah I noticed problems too on my end, and re-opened the ticket.



PRASANNA KUMAR

unread,
Aug 1, 2014, 7:23:14 AM8/1/14
to mobile-c...@googlegroups.com
Hi Traun Leyden,


is there any updated's about this issue ?

Thanks

Traun Leyden

unread,
Aug 6, 2014, 6:47:12 PM8/6/14
to mobile-c...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages