我正在将图像上传到documentDb . 我将文件名指定给 slug
属性 . 我使用上传期间获得的 media link
检索附件 .
我的期望是,当我检索附件时,我会得到我的文件名 . 但相反,Azure返回 slug
为null . 我检索到的附件的双重检查内容是正确的 .
两个问题:
-
我是否误用
slug
property ? -
我应该在哪里分配自定义属性?
这是我的代码:
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;
}
1 回答
您确定正确设置了内容类型吗?
根据this documentation,仅在上传原始媒体时才需要slug和contentype,这是您的方案 . 此外,您是否检查过azure门户中的Documents Explorer以查看文档及其附件的存储方式?那里显示的值是您期望的吗?
根据相同的文档,这是一个示例,说明原始媒体的POST应如何: