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