Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
pxgo opened this issue Oct 9, 2018 · 2 comments
Open

Comments

@pxgo
Copy link

pxgo commented Oct 9, 2018

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
Copy link
Author

pxgo commented Oct 9, 2018

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
Copy link
Author

pxgo commented Oct 9, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant