有没有办法为urlCreator.createObjectURL(blob)创建文件名

时间:2016-04-29 01:20:23

标签: javascript

我不熟悉Javascript,有没有办法可以创建自己的文件名?会发生什么是打开一个新选项卡,文件名是Guid格式。

if (urlCreator && headers['content-type'] != 'application/octet-stream') {
  // Fallback to $window.location method
  try {
    // Prepare a blob URL
    // Use application/octet-stream when using $window.location to force download
    var objectUrl = urlCreator.createObjectURL(blob);
    $window.open(objectUrl);
    success = true;
  } catch (ex) {
    //console.log("Download link method with $window.location failed with the following exception:");
    //console.log(ex);
  }
}

1 个答案:

答案 0 :(得分:0)

您可以使用FileSaver.js

var FileSaver = require('file-saver');
var blob = new Blob(["Hello, world!"], {type: "text/plain;charset=utf-8"});
FileSaver.saveAs(blob, "hello world.txt");