如何批量上传 Couchdb 附件?
我正在将 sqlite 数据库转换为 Couchdb。我可以转换数据库并上传到 Couchdb 服务器。除了图像之外的一切。我想将图像作为独立附件上传,并且我想使用 javascript、REST 和 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] }}}
我已经卷曲了一个文件来测试并且有效。我该如何批量操作?
这是使用 Appcelerator Titanium 开发的 iOS 应用程序。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该能够调整单个文件,并执行类似以下操作:
数据为:
但是,根据附件的数量和大小,您可能会遇到问题。最好是简单地循环并一次执行一个;或者至少是合理大小的批次。
You should be able to adjust your single file, and do something like the following:
with the data being:
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.
一个简单的解决方法..首先将所有数据导出到 Excel。然后创建一个列,其中包含为每个文档执行curl语句所需的确切url(在Excel中,每个文档都有行)。
执行图像上传的简单curl语句:
在建立curl所需的各个url之后(这在excel中非常容易),将所建立的url的整列复制到文本文件中,并将该文本文件放置在要上传的图像所在的位置展示。然后创建一个 bash 脚本,该脚本将读取所有行并继续将图像发布到 couchdb 服务器:
bash 脚本
在我的例子中,所有 url 行都存在于 test.txt 文件中。
这种方法对我来说非常有效,尽管有 380 个文档,但图像的大小约为 60-65kb。不确定大文件会发生什么。
A simple work around..Export all data to excel first. Then create a column which will have the exact urls needed for executing the curl statements for every docs(in the excel there will be rows for every documents).
Simple curl statement to execute image upload:
After building up the individual urls required for curl, which will be pretty easy in excel, copy the entire column of built up urls in a text file and place the text file where the images to be uploaded are present. Then create a bash script to which will read all the lines and keep on posting the images to the couchdb server:
bash script
In my case all the url lines are present in the test.txt file.
This method has worked for me flawlessly the size of the images were around 60-65kb though with 380 docs. Not sure what will happen with large files.