如何批量上传 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] }}}
我已经卷曲了一个文件进行测试,并且有效.我如何批量处理?
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屋!