Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I bulk upload Couchdb attachments?

I am converting my sqlite database to Couchdb. I can convert the db and upload to the Couchdb server. Everything but the images. I want to upload the images as standalone attachments and I would like to do this in bulk using javascript, REST, and xhr.

POST http://127.0.0.1:5984/database/_bulk_docs

Data : {"_id": "701", "_attachments": {"555_image.png": { "content_type": "image/jpg","data":[object TiFilesystemFile]      }}}

I have CURLed a single file to test and that works. How do I do bulk?

This is and iOS app developed with Appcelerator Titanium.

like image 786
user1036437 Avatar asked Nov 05 '22 09:11

user1036437


1 Answers

You should be able to adjust your single file, and do something like the following:

POST http://127.0.0.1:5984/database/_bulk_docs

with the data being:

{
  "docs": [
    {"_id": "701", "_attachments": {"555_image.png": { "content_type": "image/jpg","data":[object TiFilesystemFile] }},
    {"_id": "702", "_attachments": {"556_image.png": { "content_type": "image/jpg","data":[object TiFilesystemFile] }},
    {"_id": "703", "_attachments": {"557_image.png": { "content_type": "image/jpg","data":[object TiFilesystemFile] }},
  ]
}

However, depending on the number and size of attachments you might run into problems. It might be better to simply loop and do them one at a time; or at least in reasonably sized batches.

like image 159
Colin Ross Avatar answered Nov 09 '22 10:11

Colin Ross