【问题标题】:How to assign file-name to Azure DocumentDB attachment?如何将文件名分配给 Azure DocumentDB 附件?
【发布时间】:2015-01-04 10:17:16
【问题描述】:

我正在将图像上传到 documentDb。我将文件名分配给 slug 属性。我使用上传期间获得的media link 检索附件。

我的期望是,当我检索附件时,我会找回我的文件名。但相反,Azure 将 slug 返回为 null。我已经仔细检查了检索到的附件的内容是否正确。

两个问题:

  1. 我是否滥用了slug 属性?
  2. 我应该在哪里分配自定义属性?

这是我的代码:

public async Task<string> UploadAttachment(string selfLinkId, Stream mediaStream, string contentType, string fileName)
{            
    Document foundDocument = (await _client.ReadDocumentAsync(selfLinkId)).Resource;
    ResourceResponse<Attachment> resp = await _client.CreateAttachmentAsync(foundDocument.AttachmentsLink, mediaStream, new MediaOptions { ContentType = contentType, Slug = fileName, });
    string mediaLink = resp.Resource.MediaLink;
    return mediaLink;
}

public async Task<MediaResponse> GetAttachment(string mediaLink)
{
    //Use DocumentClient to read the Media content
    MediaResponse content = await _client.ReadMediaAsync(mediaLink);
    return content;
}

【问题讨论】:

    标签: azure azure-cosmosdb


    【解决方案1】:

    您确定内容类型设置正确吗?

    根据this documentation, slug 和 contentype 仅在上传原始媒体时才需要,这是您的方案。此外,您是否检查过 azure 门户中的文档资源管理器以查看文档及其附件的存储方式?那里显示的值是您期望的值吗?

    根据相同的文档,这是原始媒体 POST 的示例:

    POST https://contosomarketing.documents.azure.com/dbs/hUwBcw==/colls/hUwBc+gfDX4=/docs/hUwBc+gfDX4DAAAAAAAAAA==/attachments HTTP/1.1
    x-ms-date: Thu, 14 Aug 2014 22:40:25 GMT
    authorization: type%3dmaster%26ver%3d1.0%26sig%3dza46lCo9nNr0%2fGMjryG8S%2b26ZsFABUYPlW3ebq26nDg%3d
    x-ms-version: 2014-08-21
    Content-Type: image/png
    Slug: brush.png
    Content-Length: 244
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-04-27
      • 2022-01-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-27
      相关资源
      最近更新 更多