我正在使用谷歌云存储。此代码将在存储桶中保存一个对象,但它只是空的。它显示大小为 0 字节
req.file = req.files.file;
const bucketName = req.body.bucketName || DEFAULT_BUCKET_NAME;
const bucket = storage.bucket(bucketName);
const gcsFileName = `${Date.now()}-${req.file.name}`;
const file = bucket.file(gcsFileName);
const stream = file.createWriteStream({
// resumable: false,
// gzip: true,
metadata: {
contentType: req.file.mimetype,
},
});
stream.on('error', (err) => {
req.file.cloudStorageError = err;
next(err)
});
stream.on('finish', () => {
console.log('image uploaded succesfully')
req.file.cloudStorageObject = gcsFileName;
return file.makePublic()
.then(() => {
req.file.gcsUrl = gcsHelpers.getPublicUrl(bucketName, gcsFileName);
next()
});
});
stream.end(req.files.file.buffer);