如何使用 Java 在 CouchDB 中存储 Blob?
How to store Blob in CouchDB using Java?
我有一个 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);
...
显然您需要异常处理和错误检查。
我有一个 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);
...
显然您需要异常处理和错误检查。