0

FileResult を使用して、Web サイトのファイルを次のように表示しています。

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>

何が問題なのですか、どうすれば修正できますか?

4

1 に答える 1

0

最終的に、私は解決策を見つけました。
アクションを次のように変更する必要がありました。

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);
}
于 2014-11-03T18:26:58.270 に答える