簡體   English   中英

如何在 Azure Cosmos DB 中存儲圖像?

[英]How can I store Images in Azure Cosmos DB?

我有 PNG 圖像,我想將其與一些元數據一起存儲在 cosmos db 中。 最好的存儲方法是什么? 我不想單獨存儲在 Azure blob 存儲中,最好與數據一起存儲。

如果要將圖像直接存儲到 cosmos db,可以使用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" 
    });
}

管理外部存儲的附件本身並沒有任何內置功能。 相反,由您來存儲它們然后引用它們。

最常見的模式是將特定附件的 URL 與文檔一起存儲(例如,存儲到 Azure 存儲中的 blob)。

注意:通常您將圖像添加到 CosmosDB 中,查詢會花費很多。 推薦的做法是將圖像存儲在 Azure Blob 中並在 Cosmos DB 文檔中添加鏈接,您可以利用 Azure CDN 之類的東西,這將使您的圖像在您的移動設備上加載得更快。

所有附件的總大小是有限制的。

我發表了一篇博客文章,顯示了一個比較。

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

我將要發表一篇文章,展示如何使用Function App接收Form-Post,並保存文件附件。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM