Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return new Promise((resolve, reject) => {
fs.createReadStream(file)
.pipe(upload({ bucket, file }))
.on('progress', (progress) => {
console.log('Progress event:')
console.log('\t bytes: ', progress.bytesWritten);
const pct = Math.round(progress.bytesWritten/fileSize*100);
console.log(`\t ${pct}%`)
})
.on('finish', () => {
console.log('Upload complete!');
resolve();
})
.on('error', (err) => {
console.error('There was a problem uploading the file :(');
reject(err);
})
});
}
startResumableUpload_(dup, options) {
options = extend(
{
metadata: {},
},
options
);
const uploadStream = resumableUpload.upload({
authClient: this.storage.authClient,
bucket: this.bucket.name,
file: this.name,
generation: this.generation,
key: this.encryptionKey,
kmsKeyName: this.kmsKeyName,
metadata: options.metadata,
offset: options.offset,
predefinedAcl: options.predefinedAcl,
private: options.private,
public: options.public,
uri: options.uri,
userProject: options.userProject,
});
uploadStream
createResumableUpload(options, callback) {
if (is.fn(options)) {
callback = options;
options = {};
}
resumableUpload.createURI(
{
authClient: this.storage.authClient,
bucket: this.bucket.name,
file: this.name,
generation: this.generation,
key: this.encryptionKey,
kmsKeyName: this.kmsKeyName,
metadata: options.metadata,
offset: options.offset,
origin: options.origin,
predefinedAcl: options.predefinedAcl,
private: options.private,
public: options.public,
userProject: options.userProject,
},
callback
File.prototype.createResumableUpload = function(options, callback) {
if (is.fn(options)) {
callback = options;
options = {};
}
resumableUpload.createURI({
authClient: this.bucket.storage.authClient,
bucket: this.bucket.name,
file: this.name,
generation: this.generation,
metadata: options.metadata,
origin: options.origin,
predefinedAcl: options.predefinedAcl,
private: options.private,
public: options.public,
userProject: options.userProject
}, callback);
};