[英]How to delete a file in Firebase Storage using firebase admin sdk
I''m developing an android app, a web server using flask and firebase. 我正在开发一个android应用程序,一个使用flask和firebase的网络服务器。 When client app uploads an image file, the web server saves an image url in database.
当客户端应用上传图像文件时,Web服务器将图像URL保存在数据库中。
And then, client app gets the image url and open image from firebase storage. 然后,客户端应用获取图像URL并从Firebase存储中打开图像。
So my web server, and app don't know file name. 因此,我的Web服务器和应用程序不知道文件名。 However, to delete a file in storage, Knowing the file's name is needed.
但是,要删除存储中的文件,需要知道文件的名称。 Only what I can get is file url.
我只能得到的是文件url。
How can my web server delete a file using file url? 我的网络服务器如何使用文件url删除文件?
The following code is for deleteting file using filename. 以下代码用于使用文件名删除文件。 I wanna change this code to deleteting file using file url.
我想将此代码更改为使用文件url删除文件。
bucket = storage.bucket('<BUCKET_NAME>')
def deleteFile(imageName):
try:
bucket.delete_blob('profile_images/' + imageName)
bucket.delete()
return True
except Exception as e:
print(e)
return False
The Storage client in the Firebase Admin SDK is a thin wrapper around the Node.js client for Google Cloud Storage . Firebase Admin SDK中的Storage客户端是Google Cloud Storage的Node.js客户端的瘦包装。 And as far as I know the latter doesn't have a way to map the download URL back to a
File
. 据我所知,后者没有办法将下载URL映射回
File
。
This means that you'll have to find the path from the client using FirebaseStorage.getReferenceFromUrl()
, and then pass that path to your web server. 这意味着您必须使用
FirebaseStorage.getReferenceFromUrl()
从客户端找到路径,然后将该路径传递到Web服务器。 That way the JavaScript code can use the path to create a reference to the File
. 这样,JavaScript代码可以使用路径创建对
File
的引用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.