Get error status: 403 ONLY when trying to update a document and calling setAttachment on the new revision

55 views
Skip to first unread message

saif khan

unread,
Dec 12, 2014, 12:17:20 PM12/12/14
to mobile-c...@googlegroups.com
Im trying to upload an image to a document, here is my code to upload the bitmap

                       
 
if (bmp == null) {
   
Timber.e("Bitmap loading failed");
   
return;
 
}
 
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
  bmp
.compress(Bitmap.CompressFormat.JPEG, 75, outputStream);
 
InputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());




 
Document doc = database.getDocument(currentUser.id);
 
UnsavedRevision newRev;
 
try {
      newRev
= doc.getCurrentRevision().createRevision();
      newRev
.setAttachment(
             
"profileImage",
             
"image/jpg",
              inputStream
);
      newRev
.save();
 
} catch (CouchbaseLiteException e) {
      e
.printStackTrace();
 
}




When i try to upload this image i get this error

Got error status: 403 for {url}/db/{uuid}?new_edits=false.  Reason: Forbidden


Doing the same thing but not calling set attachment with my bitmap allows the doc to upload. Updating any of the properties of the new doc doesn't return a 403, but if you add an attachment it gives a 403 and doesnt sync with server but seems to update locally.

Im on android using couchbase-lite-android:1.0.3





Saif Khan

unread,
Dec 12, 2014, 4:59:24 PM12/12/14
to mobile-c...@googlegroups.com
For additional info, we are using a node server with sync gateway. Here are the sync gateway logs from when we try to upload an image.

//GOOD REQUEST THAT SUCCEEDED
21:20:52.485430 HTTP:  #366: PUT /todos/<id 1>?new_edits=false  (as <id 1>)
21:20:52.489843 CRUD: Stored doc "<id 1>" / "8-ea19fa2623e8c7968650784221218e40"
// FAILED REQUEST
21:18:08.827785 HTTP:  #163: GET /todos/_changes?feed=longpoll&limit=50&heartbeat=300000&style=all_docs&since=30424  (as <id 2>)
21:18:08.866507 HTTP:  #164: POST /todos/_revs_diff  (as <id 2>)
21:18:09.107948 HTTP:  #165: PUT /todos/<id 2>?new_edits=false
21:18:09.110896 Sync fn rejected: new=map[_rev:12-4d6c6fcc9fa0f028a4b5a6500ffa5f76 _attachments:map[profileImage:map[stub:true digest:sha1-GFxTm7f5N2Ott83RimyU+l/QKLM= revpos:12 content_type:image/jpg length:55321]] userId:<id 2> goal:strength type:user _revisions:map[start:12 ids:[4d6c6fcc9fa0f028a4b5a6500ffa5f76 cc5445fe9f9ad2ee1f4f0e16be811303 11a90b24bc9f0c2a3f7a714004860f22 718a3cd4e2dd4091a8729b9960fbdf05]] skillLevel:beginner weightUnit:kgs homeGym: gender:m heightUnit:cm _id:<id 2>]  old={"gender":"m","goal":"strength","heightUnit":"cm","homeGym":"","type":"user","userId":"<id 2>","weightUnit":"kg"} --> 403 missing channel access
21:18:09.111048 HTTP: #165:     --> 403 missing channel access  (3.3 ms)


NOTE: the good request is from our iOS app and the failed request is from out android app. One difference in the logs we noticed was that the (as <id 2>) doesnt appear for the put request in the failure case. Maybe the cookie is not being sent up in the failure case?

Traun Leyden

unread,
Dec 12, 2014, 7:10:54 PM12/12/14
to mobile-c...@googlegroups.com
Can you post a snippet of your sync gateway config, as well as the java code where you kick off the replication?



--
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/a6cbdb31-b559-4993-be58-744da5fe4f0f%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Traun Leyden

unread,
Dec 12, 2014, 7:10:56 PM12/12/14
to mobile-c...@googlegroups.com
Can you post a snippet of your sync gateway config, as well as the java code where you kick off the replication?


On Fri, Dec 12, 2014 at 1:59 PM, Saif Khan <saifk...@gmail.com> wrote:

Jens Alfke

unread,
Dec 12, 2014, 7:30:22 PM12/12/14
to mobile-c...@googlegroups.com

> On Dec 12, 2014, at 1:59 PM, Saif Khan <saifk...@gmail.com> wrote:
>
> NOTE: the good request is from our iOS app and the failed request is from out android app. One difference in the logs we noticed was that the (as <id 2>) doesnt appear for the put request in the failure case. Maybe the cookie is not being sent up in the failure case?

Yeah, that's weird — the _revs_diff request is made as "<id 2>", but the document PUT that follows is unauthenticated and made as guest (which is presumably why the sync function rejected it.)

Sounds like a bug in the Android replicator?

—Jens

Traun Leyden

unread,
Dec 12, 2014, 7:34:17 PM12/12/14
to mobile-c...@googlegroups.com

Yeah, that's weird — the _revs_diff request is made as "<id 2>", but the document PUT that follows is unauthenticated and made as guest (which is presumably why the sync function rejected it.)

Sounds like a bug in the Android replicator?


Agreed.  @Saif can you file a bug in couchbase-lite-java-core?


 
—Jens


--
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.

Saif Khan

unread,
Dec 15, 2014, 11:27:51 AM12/15/14
to mobile-c...@googlegroups.com
OK I will do that. Thanks guys. 

Traun Leyden

unread,
Dec 15, 2014, 1:19:17 PM12/15/14
to mobile-c...@googlegroups.com
Thanks, I will look for it.

By the way, in ToDoLite-Android, we create documents with attachments and use facebook auth.  You may want to compare your code with the ToDoLite-Android code.


Reply all
Reply to author
Forward
0 new messages