简体   繁体   English

云功能:从存储中删除文件

[英]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: 两种选择:

  1. Just try both extensions. 只需尝试两个扩展。
  2. Store the name in a database ahead of time so you know it for sure later on. 提前将名称存储在数据库中,以便以后确定。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从云功能中删除云存储中的文件 - Delete file in cloud storage from cloud functions 将存储在 Cloud Storage 中的 Apple Wallet.pkpass 文件从 Firebase Cloud Functions 更新到设备 - Updating Apple Wallet .pkpass file stored in Cloud Storage from Firebase Cloud Functions to device 无法使用Firebase功能删除Google Cloud Storage文件 - Cannot delete Google Cloud Storage files using Firebase Functions 同时删除 Cloud Firestore 文档和 Fire Storage 文件 - delete Cloud Firestore doc and Fire Storage file simultaneously 云存储文件下载后如何删除? - How to delete a Cloud Storage file after it has been downloaded? 从 Google Cloud Functions (JS) 中运行 Google Storage Command - Running Google Storage Command from within Google Cloud Functions (JS) 如何从 Firebase 云存储中删除图像 - 反应 - How to Delete Image from Firebase cloud Storage - REACT Firebase Polymer从存储中删除文件 - Firebase Polymer delete file from storage 如何从Firebase Cloud功能删除用户数据(任何数据)? - How to delete user data (any data) from Firebase Cloud functions? 如何使用 Cloud Functions 从 Firestore 中的 ArrayList Map 中删除 object? - How to delete an object from an ArrayList Map in Firestore using Cloud Functions?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM