Node.js Firebase函数:错误:无法打开进行写入

Node.js Firebase函数:错误:无法打开进行写入,node.js,firebase,google-cloud-functions,Node.js,Firebase,Google Cloud Functions,所以我试图实现一个firebase函数。我转到firebase函数库示例并复制了它。一切正常,“部署完成!”,没有错误迹象。但是,当我尝试将图像上载到firebase存储时,firebase函数无法打开它 我使用了一个代码: const functions=require('firebase-functions'); const admin=require('firebase-admin'); admin.initializeApp() const{Storage}=require(“@goog

所以我试图实现一个firebase函数。我转到firebase函数库示例并复制了它。一切正常,“部署完成!”,没有错误迹象。但是,当我尝试将图像上载到firebase存储时,firebase函数无法打开它

我使用了一个代码:

const functions=require('firebase-functions');
const admin=require('firebase-admin');
admin.initializeApp()
const{Storage}=require(“@googlecloud/Storage”);
const gcs=新存储();
const path=require('path');
const os=要求('os');
常数fs=要求('fs');
常量夏普=要求(“夏普”);
exports.generateThumbnail=functions.storage.object().onFinalize(异步(对象)=>{
const fileBucket=object.bucket;//包含文件的存储桶。
const filePath=object.name;//存储桶中的文件路径。
const contentType=object.contentType;//文件内容类型。
const metageneration=object.metageneration;//已生成元数据的次数。新对象的值为1。
如果(!contentType.startsWith('image/')){
返回console.log('这不是映像');
}
const fileName=path.basename(filePath);
if(fileName.startsWith('thumb_')){
返回console.log('已经是缩略图');
}
const bucket=admin.storage().bucket(fileBucket);
const tempFilePath=path.join(os.tmpdir(),文件名);
log('Created temporary path',tempFilePath);
常量元数据={
contentType:contentType,
};
wait bucket.file(filePath).download({目的地:tempFilePath});
log('本地下载到的映像',tempFilePath);
常量thumbFileName=`thumb_${fileName}`;
const thumbFilePath=path.join(path.dirname(filePath),thumbFileName);
log('Created thumb path',tempFilePath);
常数大小=200;
/*wait*/sharp(tempFilePath).resize(size,size).toFile(thumbFilePath);
等待bucket.upload(tempFilePath{
目标:文件路径,
元数据:元数据,
});
返回fs.unlinkSync(tempFilePath);
});
错误:


除了
/tmp
目录之外,云函数有一个只读文件系统。您必须确保将数据写入路径
/tmp/您的文件

文件系统中唯一可写的部分是/tmp目录,它 可以使用在函数实例中存储临时文件。这是一个 本地磁盘装入点,称为“tmpfs”卷,其中写入数据 该卷存储在内存中。请注意,它将消耗内存 为函数配置的资源