Я проверял этот пример кода:
// 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"