如何批量上传Couchdb附件? [英] How do I bulk upload Couchdb attachments?
问题描述
我正在将sqlite数据库转换为Couchdb.我可以转换数据库并上传到Couchdb服务器.除了图像以外的所有内容.我想将图像作为独立的附件上传,我想使用javascript,REST和xhr批量进行此操作.
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] }}}
我已经对单个文件进行了CURL测试,并且可以正常工作.我该怎么做?
I have CURLed a single file to test and that works. How do I do bulk?
这是由Appcelerator Titanium开发的iOS应用.
This is and iOS app developed with Appcelerator Titanium.
推荐答案
您应该能够调整单个文件,并执行以下操作:
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
数据为:
{
"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.
这篇关于如何批量上传Couchdb附件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!