forwardemail / forwardemail/superagent
The problem of progress event when upload file
- Dominant language
- JavaScript
- Stars
- 16.6k
- Forks
- 1.3k
- PR merge metrics
- No merged PRs in 30d
Description
I'm trying to use the .on('progress', cb) method for listening the progress of file upload.But smothing worng hapend when I pass different type param to the .attach.The progrss is fine when pass the file path, but event.percent shows 100% and it took minutes before uploading to server when pass Buffer.
Relevant versions:
- superagent: 6.1.0
- @types/superagent: 4.1.10
- typescript: 4.1.2
- ts-node: 9.0.0
Pass a file path: (the file total size is 82.3MB)
````javascript
const filePath = 'path/to/the/file';
superagent.post(uploadUrl)
.attach('upload', filePath, path.basename(filePath))
.on('progress', event =>{
console.log(event.loaded)
})
.end((err, res) => {
if(!err) console.log(res.status)
})
````
result:
````shell
181
65717
131253
196789
262325
327861
393397
458933
524469
590005
655541
721077
786613
852149
917685
983221
.....
.....
85328053
85393589
85459125
85524661
85590197
85655733
85721269
85786805
85852341
85917877
85983413
86048949
86114485
86180021
86245557
86302755
86302757
86302858
86302859
86302861
86302967
86302969
86303027
200
````
The loaded is increase slowly。When loaded = totalSize,upload action is finished。
Pass Buffer
````javascript
const filePath = 'path/to/the/file';
superagent.post(uploadUrl)
.attach('upload', fs.readFileSync(filePath), path.basename(filePath))
.on('progress', event =>{
console.log(event.loaded)
})
.end((err, res) => {
if(!err) console.log(res.status)
})
````
result
````shell
181
86302755
86302757
86302858
86302859
86302861
86302967
86302969
86303027
// Wait half a minute here
200
````
The loaded increase so fask. Loaded = totalSize and it took minutes before uploading to server.
Contributor guide
Assessment
This issue has not been assessed yet.