首页 > 解决方案 > 如何使用 RestAPI java 客户端在 couchDB 中创建附件

问题描述

我需要在 CouchDB 上存储附件。我将如何使用 Java 来做到这一点。我可以使用哪些 API?我可以参考任何示例代码或文档吗?目前我们正在使用 cloudantdb,但我们计划在 Azure 上使用 CouchDB

com.cloudant.client.api.Database;com.cloudant.client.api.model.Response;

谢谢

标签: azurenosqlcouchdbbitnami

解决方案


如果您使用LightCouch Java API

InputStream in =  // .. init stream

// save under a new document, a generated UUID is assigned as id.
Response response = dbClient.saveAttachment(in, "photo.png", "image/png");

// save to an existing document
dbClient.saveAttachment(in, "file.pdf", "application/pdf", "doc-id", "doc-rev");

// save under a new document with the given id. 
dbClient.saveAttachment(in, "photo.jpeg", "image/jpeg", "doc-id", null);

// get attachment
InputStream in = dbClient.find("doc-id/photo.jpeg");
// ..
in.close(); // close the stream

推荐阅读