【发布时间】:2017-12-21 14:25:31
【问题描述】:
我正在检查这个示例代码:
// Download file from bucket.
const bucket = gcs.bucket(fileBucket);
const tempFilePath = path.join(os.tmpdir(), fileName);
return bucket.file(filePath).download({
destination: tempFilePath
}).then(() => {
console.log('Image downloaded locally to', tempFilePath);
// Generate a thumbnail using ImageMagick.
return spawn('convert', [tempFilePath, '-thumbnail', '200x200>', tempFilePath]);
}).then(() => {
console.log('Thumbnail created at', tempFilePath);
// We add a 'thumb_' prefix to thumbnails file name. That's where we'll upload the thumbnail.
const thumbFileName = `thumb_${fileName}`;
const thumbFilePath = path.join(path.dirname(filePath), thumbFileName);
// Uploading the thumbnail.
return bucket.upload(tempFilePath, {destination: thumbFilePath});
// Once the thumbnail has been uploaded delete the local file to free up disk space.
}).then(() => fs.unlinkSync(tempFilePath));
我的问题具体在这一行:
return bucket.upload(tempFilePath, {destination: thumbFilePath});
为什么我们在这里提供destination 参数的完整文件路径?据我了解,destination 参数表示上传到存储桶后将采用的文件名。
所以我的猜测是 "thumb_Qsdflsdfa.png" 就足够了,而不是 "/tmp/../thumb_Qsdflsdfa.png"
【问题讨论】:
标签: firebase google-cloud-storage google-cloud-functions