2016-04-29 121 views
3

私はJavascriptに慣れていません。私自身のファイル名を作成する方法はありますか?新しいタブが開き、ファイル名がGuid形式になります。urlCreator.createObjectURL(blob)のファイル名を作成する方法があります

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); 
    } 
} 
+0

@Kaiidoに返答してくれてありがとう、それに関する病気の研究:) – gab

+0

@Kaiido、最後に、私はそれを保存する予定はありませんでした。データはすでにバックエンドからのもので、ファイル名でブラウザに表示したいだけです。 – gab

答えて

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"); 
関連する問題