文件路径结果不适用于 swf 文件?



我使用FileResult在我的网站中显示文件如下:

public ActionResult GetSwf(long id = 0)
{
    if (id <= 0) return null;
    Attachment attachment = Service.GetAttachmentById(id);
    if (attachment == null) return null;
    string filename = attachment.Name;
    string mimeType = "application/x-shockwave-flash";
    string absoluteFilePath = UploadedPaths.GetAbsolutePath(attachment.Path);
    return File(absoluteFilePath, mimeType, filename);
}

它不适用于以下标记,浏览器将下载文件而不是显示它!

<object type="application/x-shockwave-flash" width="220" height="166" data="File/GetSwf/1232" class="flash-object" data-name="ads-file"></object>

怎么了,我该怎么修?

最终,我找到了解决方案
我不得不将操作更改为以下内容:

public ActionResult GetSwf(long id = 0)
{
    if (id <= 0) return null;
    Attachment attachment = Service.GetAttachmentById(id);
    if (attachment == null) return null;
    string filename = attachment.Name;
    string mimeType = "application/x-shockwave-flash";
    string absoluteFilePath = UploadedPaths.GetAbsolutePath(attachment.Path);
    byte[] bytes = System.IO.File.ReadAllBytes(absoluteFilePath);
    return new FileContentResult(bytes, mimeType);
}

相关内容

  • 没有找到相关文章

最新更新