send icon indicating copy to clipboard operation
send copied to clipboard

The total size of the file could not be obtained when downloading the file

Open pxgo opened this issue 7 years ago • 2 comments

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.

pxgo avatar Oct 09 '18 02:10 pxgo

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'?

pxgo avatar Oct 09 '18 06:10 pxgo

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);

pxgo avatar Oct 09 '18 07:10 pxgo