代码之家  ›  专栏  ›  技术社区  ›  Pankaj Rawat

Cosmos DB图像/文件附件

  •  1
  • Pankaj Rawat  · 技术社区  · 7 年前

    我用下面的代码创建了一个带有pdf附件的文档,它正在工作(能够检索附件)。

    var myDoc = new { id = "42", Name = "Max", City="Aberdeen" }; // this is the 
    document you are trying to save
    var attachmentStream = File.OpenRead("c:/Path/To/File.pdf"); // this is the 
    document stream you are attaching
    
    var client = await GetClientAsync();
    var createUrl = UriFactory.CreateDocumentCollectionUri(DatabaseName, 
    CollectionName);
    Document document = await client.CreateDocumentAsync(createUrl, myDoc);
    
    await client.CreateAttachmentAsync(document.SelfLink, attachmentStream, new 
    MediaOptions()
    {
        ContentType = "application/pdf", // your application type
        Slug = "78", // this is actually attachment ID
    });
    

    有谁能帮助我理解内置附件功能的价值吗?这怎么比blob和其他选项好呢?cosmos DB在哪里保持连接?

    1 回复  |  直到 7 年前
        1
  •  0
  •   Jay Gong    7 年前

    有谁能帮助我理解内置附件的价值吗

    基于此 official doc ,你可以得到你问题的答案。

    可以存储两种类型的数据:

    2.存储在远程媒体存储器中的媒体的元数据(例如,位置、作者等)

    Azure Cosmos DB将确保在所有 上载新媒体并填充时生成附件 指向新添加媒体的媒体。如果你选择储存 OneDrive、Azure存储、DropBox等),您仍然可以使用附件 引用媒体。在这种情况下,您将创建附件

    所以,据我所知,如果你的资源数据会经常被添加或删除,我想你可以考虑使用附件。您只需将远程URL存储到媒体属性中。

    cosmos DB在哪里保持连接?

    collection 作为JSON格式的文档,可以使用restapi或任何客户端sdk轻松地创建、替换、删除、读取或枚举它。据我所知,目前还不能在门户网站上显示。

    BTW,Azure COSMOS DB通常比BLB存储更昂贵,我认为成本是一个重要的考虑因素。更多细节,你可以参考 price doc .

    推荐文章