我有一个Blob,想将其存储到Java中的Apache CouchDb中。我得到这样的斑点
Blob blob1 = blobStore.getBlob(containerName, fileName);
如何将其存储在CouchDB中?
最佳答案
我没有进行测试的设置,但是在查看文档时,您想要执行以下操作:
...
Blob blob = blobStore.getBlob(containerName, fileName);
InputStream is = blob.getPayload.openStream();
String contentType = "image/jpeg"; //or whatever content the blob is.
AttachmentInputStream ais = new AttachmentInputStream("attachment_id", is, contentType);
db.createAttachment("new_document_id", ais);
...
显然,您将需要异常处理和错误检查。