ユーザーにファイルのダウンロードを要求しない非同期ファイルのダウンロード方法を作成しました。エラーはなく、コードとjqueryは正常に実行されますが、ブラウザーはダウンロードを要求しません。私はSOのすべての解決策を見てきましたが、私のものはうまくいかないようです。
public async Task<HttpResponseMessage> Method(string data)
{
//do stuff
response.StatusCode = HttpStatusCode.OK;
response.Content = new StreamContent(new FileStream(downloadFileName, FileMode.Open, FileAccess.Read));
response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment");
response.Content.Headers.ContentDisposition.FileName = myFileName;
response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
return response;
}
$ .getの完了後にiframeを追加し、そのソースを変更すると、ブラウザーでダウンロードダイアログが開きます。
function callback(result) {
$('#myFrame').attr('src', '/worksitefileservice/api/xfer/download?data=' + encodeURIComponent(json));
}
<iframe id="myFrame" style="visibility:hidden;display:none;" src=""></iframe>
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加