Skip to content

Commit

Permalink
fix: make uploads resumable
Browse files Browse the repository at this point in the history
  • Loading branch information
digitalsadhu committed Jun 26, 2024
1 parent 933d5db commit 3f35e1f
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,25 +66,30 @@ const SinkGCS = class SinkGCS extends Sink {
}

const src = this._bucket.file(pathname);
const gcsStream = src.createWriteStream({
resumable: false,
metadata: {
cacheControl: 'public, max-age=31536000',
contentType,
},
timeout: this._writeTimeout,
gzip: this._writeGzip,
});
src.createResumableUpload().then(([resumableUpload]) => {
const gcsStream = src.createWriteStream({
resumable: true,
uri: resumableUpload,
metadata: {
cacheControl: 'public, max-age=31536000',
contentType,
},
timeout: this._writeTimeout,
gzip: this._writeGzip,
});

gcsStream.on('error', () => {
this._counter.inc({ labels: { access: true, operation } });
});

gcsStream.on('error', () => {
this._counter.inc({ labels: { access: true, operation } });
});
gcsStream.on('finish', () => {
this._counter.inc({ labels: { success: true, access: true, operation } });
});

gcsStream.on('finish', () => {
this._counter.inc({ labels: { success: true, access: true, operation } });
resolve(gcsStream);
}).catch((error) => {
reject(error);
});

resolve(gcsStream);
});
}

Expand Down

0 comments on commit 3f35e1f

Please sign in to comment.