send
send copied to clipboard
The total size of the file could not be obtained when downloading the file
When using Google Chrome to download, the download progress bar cannot reflect the current download status, only the size of the downloaded file can be seen, and the total size of the file cannot be seen.
This problem is not caused by koa-send. The reason is because I used koa-body and set
ctx.body = ctx.request.body
This causes the subsequent
ctx.body = fs.createReadStream(filePath)
problem to get the total size of the downloaded file.
Do you have a good solution without changing 'ctx.body = ctx.request.body'?
Can be solved by the following methods
before
ctx.set('Content-Length', fileSize);
ctx.body = fs.createReadStream(filePath);
after
ctx.body = fs.createReadStream(filePath);
ctx.set('Content-Length', fileSize);