如何将图像存储在Azure Cosmos DB中? [英] How can I store Images in Azure Cosmos DB?

查看:60
本文介绍了如何将图像存储在Azure Cosmos DB中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有要与一些元数据一起存储在cosmos db中的PNG图像.最好的存储方式是什么?我不想单独存储在Azure blob存储中,最好与数据一起存储.

I have PNG images which i want to store in cosmos db along with some metadata. What is the best way to store it ? I don't want to store in Azure blob storage separately, better to store with the data.

推荐答案

如果要将图像直接存储到cosmos数据库,则可以使用

If you want to store images directly to the cosmos db, you can use DocumentClient.CreateAttachmentAsync method to store it directly.

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" 
    });
}

没有内部内置的东西可以管理外部存储的附件.而是由您存储它们然后引用它们.

There's nothing inherently built-in to manage externally-stored attachments. Rather, it's up to you to store them and then reference them.

最常见的模式是将URL随文档一起存储到特定附件(例如,存储到Azure存储中的Blob).

The most common pattern is to store a URL to the specific attachment, with a document (e.g. to a blob in Azure Storage).

注意::通常,您是将图像添加到CosmosDB中,这将使查询花费很多.推荐的方法是将图像存储在Azure Blob中并在Cosmos DB文档中添加链接,您可以利用Azure CDN之类的优势,这将使图像在移动设备上的加载速度更快.

NOTE: Generally you are adding images into CosmosDB, it will costs you much for queries. Recommended way is to do is to store the image in Azure Blob and add the link in the Cosmos DB document you can take advantage of things like Azure CDN that will make your images load faster for your mobile.

这篇关于如何将图像存储在Azure Cosmos DB中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆