Node Google Drive Api v3 upload file progress

144 Views Asked by At

i want to show upload progress when uploading big files. i am using googleapis npm package, drive_v3. Same question asked for download progress and answered with some workaround using streams. unfortunately i cant get it working with upload.

sample code is here

// drive:drive_v3.Drive
let response = await this.drive.files.create({
    media: {
        body: buffer
    },
    fields: 'id',
}, {
    // this event is deprecated and ignored :C
    onUploadProgress(ev) {
    }
})

i tried onUploadProgress event, which is deprecated not working. tried some stream approach but didn't success.

1

There are 1 best solutions below

0
On

Well I managed to get upload progress on nodejs google drive api. As I said before, used a stream based workaround by using progress_stream package.

let filePath = "someFilePath.zip"    
let stream = fs.createReadStream(filePath);
let stat = fs.statSync(filePath);

let progressable = progress_stream({ length: stat.size, time: 100, })
progressable.on("progress", (e) => {
  // progress event...
  console.log("upload progress", e.percentage)
});
stream.pipe(progressable)
let body = progressable;
            
//drive:drive_v3.Drive
let response = await this.drive.files.create({
  media: {
    body: body
})