接続速度が 2 mbps 未満のクライアントに大きなファイル (1.5 GB) を送信すると、ブラウザは 1.08 GB のデータしか受信できず、ダウンロードが完了したと認識します。より高速な接続では、1.5 GB のファイル全体が受信されます。
私の Express.js アプリは、送信するファイルを特定し、次のresponse#download
メソッドで応答します。
app.get('/download-the-big-file', function(request, response) {
var file = {
name: 'awesome.file',
path: '/files/123-awesome.file'
};
response.header("X-Accel-Redirect: " + file.path);
response.download(file.path, file.name);
});
NginxXsendfileを利用するように X-Accel-Redirect ヘッダーを設定していることに注意してください
私のNginx構成:
server {
client_max_body_size 2g;
server_name localhost;
location / {
proxy_pass http://127.0.0.1:8000/;
}
location /files {
root /media/storage;
internal;
}
}