我可以使用哪些客户端 API?
您可以关注cosmos db java sdk 到 CRUD 附件。
import com.microsoft.azure.documentdb.*;
import java.util.UUID;
public class CreateAttachment {
// Replace with your DocumentDB end point and master key.
private static final String END_POINT = "***";
private static final String MASTER_KEY = "***";
public static void main(String[] args) throws Exception, DocumentClientException {
DocumentClient documentClient = new DocumentClient(END_POINT,
MASTER_KEY, ConnectionPolicy.GetDefault(),
ConsistencyLevel.Session);
String uuid = UUID.randomUUID().toString();
Attachment attachment = getAttachmentDefinition(uuid, "application/text");
RequestOptions options = new RequestOptions();
ResourceResponse<Attachment> attachmentResourceResponse = documentClient.createAttachment(getDocumentLink(), attachment, options);
}
private static Attachment getAttachmentDefinition(String uuid, String type) {
return new Attachment(String.format(
"{" +
" 'id': '%s'," +
" 'media': 'http://xstore.'," +
" 'MediaType': 'Book'," +
" 'Author': 'My Book Author'," +
" 'Title': 'My Book Title'," +
" 'contentType': '%s'" +
"}", uuid, type));
}
}
在它说的文档中,我们可以存储的总文件大小为 2GB。
“Azure Cosmos DB 允许您存储二进制 blob/媒体
Azure Cosmos DB(每个帐户最多 2 GB)“我们可以做到的最大值吗?
商店?
是的。附件的大小在文档数据库中是有限的。但是,有两种方法可以创建 Azure Cosmos DB 文档附件。
1.将文件存储为文档的附件
原始附件包含在 POST 的正文中。
必须设置两个标题:
Slug – 附件的名称。
contentType – 设置为附件的 MIME 类型。
2.将文件的 URL 存储在文档的附件中
POST 的正文包括以下内容。
id – 它是标识附件的唯一名称,即没有两个附件将共享相同的 id。 ID 不得超过 255 个字符。
媒体 – 这是附件所在的 URL 链接或文件路径。
下面是一个例子
{
"id": "device\A234",
"contentType": "application/x-zip-compressed",
"media": "www.bing.com/A234.zip"
}
如果您的文件超出限制,您可以尝试用第二种方式存储它们。更多详情请参考blog。
此外,您可能会注意到 cosmos db 附件支持
垃圾收集机制,确保在所有未完成的引用被丢弃时对媒体进行垃圾收集。
希望对你有所帮助。