【问题标题】:How to convert Blob to File in Electron如何在 Electron 中将 Blob 转换为文件
【发布时间】:2021-09-30 20:36:56
【问题描述】:

有谁知道如何在 ElectronJS 中将 Blob 转换为 File 对象。我试过了:

return new File([blob], fileName, {lastModified: new Date().getTime(), type: blob.type});

但似乎 ElectronJs 有不同的 File 对象 API:

ElectronJs 文件功能:

Chrome浏览器文件功能

我也试过了:

(blob as any).name = fileName;
(blob as any).lastModified = new Date().getTime();
return blob as File;

但也不起作用。

【问题讨论】:

    标签: javascript typescript file electron


    【解决方案1】:

    我找到了工作:

    blobToFile(blob: Blob, filename: string) {
        const fd = new FormData();
        fd.set('foo', blob, filename);
        return fd.get('foo') as File;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-01-25
      • 1970-01-01
      • 2017-06-13
      • 2015-02-17
      • 1970-01-01
      • 1970-01-01
      • 2015-03-12
      相关资源
      最近更新 更多