如何在Azure Cosmos DB中存储图像?

时间:2018-03-18 01:33:50

标签: azure-cosmosdb

我有PNG图像,我想存储在cosmos数据库中以及一些元数据。存储它的最佳方法是什么?我不想单独存储在Azure bolb存储中,更好地存储数据。

2 个答案:

答案 0 :(得分:12)

如果要将图像直接存储到cosmos数据库,可以使用 DocumentClient.CreateAttachmentAsync 方法直接存储它。

using (FileStream fileStream = new FileStream(@".\something.pdf", FileMode.Open))
{
    //Create the attachment
    Attachment attachment = await client.CreateAttachmentAsync("dbs/db_rid/colls/coll_rid/docs/doc_rid/attachments/", 
    fileStream, 
    new MediaOptions 
    { 
       ContentType = "image/jpeg", 
       Slug = "myImage.jpeg" 
    });
}

管理外部存储的附件没有固有的内置功能。相反,由你来存储它们然后引用它们。

最常见的模式是使用文档(例如,Azure存储中的blob)将URL存储到特定附件。

注意:一般情况下,您要将图像添加到CosmosDB中,查询会花费很多。建议的方法是将图像存储在Azure Blob中,并在Cosmos DB文档中添加链接,您可以利用Azure CDN之类的功能,使您的图像加载到您的移动设备上更快。

答案 1 :(得分:-1)

所有附件的总大小有限制。

我发表了一篇博客文章,展示了一个比较。

https://docdb.info/azure-cosmos-db-document-attachment-storage-comparison/

我即将发布一篇文章,展示如何使用功能应用程序接收表格 - 帖子并保存文件附件。

相关问题