如何保存具有不同名称的文件?

时间:2014-09-12 13:40:02

标签: javascript html5 google-chrome-extension

尝试使用其他名称保存文件。保存空文件(0字节)。此外,该文件没有扩展名。

var xhr = new XMLHttpRequest();
xhr.open('GET', 'http://www.html5rocks.com/static/images/profiles/ericbidelman.png', true);
xhr.responseType = 'arraybuffer';
xhr.onload = function(e) {
  var uInt8Array = new Uint8Array(this.response);

  chrome.fileSystem.chooseEntry(
    { type: 'saveFile', suggestedName: 'myfile'},
    function(writableFileEntry) {
      writableFileEntry.createWriter(function(writer) {
        writer.onwriteend = function(e) {
          console.log("Save complete!");
        };
        writer.write(new Blob(uInt8Array, {type: 'image/jpeg'})); 
      }, errorHandler);
    }
  );
}
xhr.send();

0 个答案:

没有答案