当一个文件通过CMS.File页面类型上传到ASP.NET时,我们需要在MVC端检索它。
我可以做以下事情吗?
var kntcoFile = FileProvider.GetFile(completeAlias, "en-US", "MySite").FirstOrDefault();
假设API找到了该文件,如何访问该文件的二进制数据,以便将其返回给浏览器?
发布于 2019-01-11 02:57:22
我为图像做了类似的事情,所以我修改了我的,希望能在你的场景中工作。需要注意的是,除非调用重载并传入true以返回AttachmentBinary,否则不会返回它。
public ActionResult FilePage(string completeAlias)
{
var kntcoFile = FileProvider.GetFile(completeAlias, "en-US", "MySite").FirstOrDefault();
if (kntcoFile != null)
{
DocumentAttachment attachment = kntcoFile.AllAttachments.FirstOrDefault();
if (attachment != null)
{
var attachmentBinary = AttachmentInfoProvider.GetAttachmentInfo(attachment.AttachmentID, true);
return base.File(attachmentBinary.AttachmentBinary, attachment.AttachmentMimeType);
}
}
EventLogProvider.LogInformation("GetFile", "NOTFOUND", "attachment Not Found" + completeAlias + " /");
return null;
}https://stackoverflow.com/questions/54114304
复制相似问题