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);
}
}
。私が知っている唯一の選択肢は、アンサー要素( '')を使用し、 'download'属性をあなたが望むファイル名に設定し、' href'をあなたが持っているobjectURLに設定することです。しかし、あなたは 'window.open()'を使用することができません。サーバにファイルを保存したい場合は、 'FormData'オブジェクトを使ってblob(objectURL!ではなく)を送信し、3番目あなたの望むファイル名に 'FormData.append()'のパラメータを追加します。 – Kaiido
@Kaiidoに返答してくれてありがとう、それに関する病気の研究:) – gab
@Kaiido、最後に、私はそれを保存する予定はありませんでした。データはすでにバックエンドからのもので、ファイル名でブラウザに表示したいだけです。 – gab