javascript - Node.js:可以将 BLOB 转换为文件并使用 shell 使用默认应用程序打开它吗?
问题描述
使用shell,我们可以通过其默认应用程序打开文件。但是有可能将一个blob
转换成文件吗?
var fileurl = ''; //url of a file, example is docx file.
var filename = $(this).text().replace(/^\s+/g, '');
$.ajax({
url: fileurl,
method: 'GET',
xhrFields: {
responseType: 'blob'
},
success: function (data) {
//convert the blob into file
var file = new File([data], filename, {type: data.type, lastModified: Date.now()});
const {shell} = require('electron');
shell.openItem(file); //open the converted file with it's default application
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
我试图将 blob 转换为文件,认为它可能会起作用,但它失败并且错误提示Error processing argument at index 0, conversion failure from #<File>
。
解决方案
Electronshell.openItem(filepath:string)
明确要求现有本地文件的路径。https://electronjs.org/docs/api/shell#shellopenitemfullpath
除非将文件保存到某个临时位置,否则不能直接传递 blob。
推荐阅读
- java - Joda DateTime toDate 不按照 Created DateTime 返回
- selenium - 如何解决此问题“selenium webdriver 中的 chrome 浏览器兼容性问题”?
- css - Ionic 3 卡片按钮不显示在卡片的右下方
- javascript - VueJS 令牌被 vue-router beforeEach 清除
- python - 如何在没有 read_only = True 的情况下使用 openpyxl 加载和更新大于 15MB 的大型 excel 文件
- fonts - 如何在 VSCode 集成终端中更改文本的字体颜色?
- spring - 在单元测试类中找不到spring应用程序类
- c# - 将参数与 Func<> 一起使用
- text - 如何从文本文件中提取字符
- apache - Htaccess:重定向到目录中的第一个或唯一一个文件