googleapis / googleapis/google-api-nodejs-client
"onUploadProgress" not working
- Dominant language
- TypeScript
- Stars
- 12.2k
- Forks
- 2k
- Avg merge
- 1d 9h
- Merged PRs (30d)
- 24
Description
Hi, i am trying to track the progress of file upload with the onUploadProgress function but its not working
```jsconst uploadFile = async (fileObject, res, date) => {
const bufferStream = new stream.PassThrough();
bufferStream.end(fileObject.buffer);
const Filename = `${fileObject.fieldname + "_" + date + "_" + fileObject.originalname}`;
const fileSize = fileObject.buffer.length;
const media = {
mimeType: fileObject.mimeType,
body: bufferStream,
};
const fileMetadata = {
name: Filename,
parents: ['1HuCYguIQhi0OFcnhbcr2JwPwJzsVeWzJ'],
};
const upload = drive.files.create(
{
resource: fileMetadata,
media: media,
fields: 'id,name',
},
{
onUploadProgress: evt => {
const progress = (evt.bytesRead / fileSize) * 100;
readline.clearLine(process.stdout, 0);
readline.cursorTo(process.stdout, 0);
process.stdout.write(`${Math.round(progress)}% complete`);
},
}
);
try {
const response = await upload;
console.log('File uploaded successfully');
res.status(200).send(`${Filename}`);
} catch (error) {
console.error('Error uploading file:', error);
res.status(500).send('Error uploading file');
}
};
```
i found the official example for this but even that doesn't work
https://github.com/googleapis/google-api-nodejs-client/blob/main/samples/drive/upload.js
Issue: It returns the progress only when it reaches 100%
Contributor guide
Assessment
This issue has not been assessed yet.