[英]Cloud functions: Delete file from storage
I wrote a trigger function, when triggered, it will delete a file from storage with a certain name. 我写了一个触发函数,当触发时,它将从存储中删除一个具有特定名称的文件。 Problem is here, I do not know the extension of the file. 问题在这里,我不知道文件的扩展名。 It could be either .png or .jpeg. 可以是.png或.jpeg。 I tried to write some code to delete the image without regard to file extension, but It does not work. 我试图编写一些代码来删除映像,而不考虑文件扩展名,但是它不起作用。 It throws No such object
error. 它No such object
引发No such object
错误。
exports.onUserDeletion = functions.auth.user().onDelete((user) => {
const userid = user.uid
const filePath = `user_photo/${userid}.{extension}`
const file = bucket.file(filePath)
return file.delete()
})
Is there any way to achieve this? 有什么办法可以做到这一点? Or any workaround where I perfom this deletion without knowing the extension in beforehand? 还是在不知道扩展名的情况下执行此删除操作的任何解决方法?
Two options: 两种选择:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.