【问题标题】:Download .msg files in client side Reactjs在客户端 Reactjs 中下载 .msg 文件
【发布时间】:2023-03-31 00:30:01
【问题描述】:

我有一个包含多个 .msg 文件的服务器 我想让用户使用以下代码在客户端下载它们:

const download = (fileName) => {
        var FileSaver = require('file-saver');
        FileSaver.saveAs(constants.filesUploadUrl + fileName, fileName);
    }

除了 .msg 文件之外的所有数据类型都可以正常下载 它给了我“失败 - 没有文件”

有没有办法在客户端启用下载 .msg 文件?

【问题讨论】:

    标签: javascript reactjs npm


    【解决方案1】:

    原来我需要将内容类型转换为“application/vnd.ms-outlook” 因为它没有被谷歌浏览器识别为 .msg

    我的后端 ASP.Net Core 映射 MIME 类型的代码:

     }
                var provider = new FileExtensionContentTypeProvider();
                provider.Mappings[".msg"] = "application/vnd.ms-outlook";
                app.UseStaticFiles(new StaticFileOptions
                {
                    FileProvider = new PhysicalFileProvider(
                    ContentTypeProvider = provider
                });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-06-26
      • 1970-01-01
      • 2021-12-03
      • 2013-11-02
      • 2014-07-05
      • 2018-12-01
      • 1970-01-01
      • 2022-07-21
      相关资源
      最近更新 更多