将大文件 (1.5gb) 发送到连接速度 < 2mbps 的客户端会导致浏览器仅接收 1.08gb 的数据,但认为下载已完成。更快的连接接收完整的 1.5gb 文件。
我的 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);
});
请注意,我将 X-Accel-Redirect 标头设置为利用NginxXsendfile
我的 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;
}
}