如何更改已上传的Firebase存储映像文件名? [英] How can i change Firebase storage image file name which is already uploaded?
问题描述
我需要更改已在Firebase存储中上传的文件名.因为,在将图像上传到Firebase存储中后,我将URL保存在Firebase数据库中的特定子项(文件夹)下.但是,当我将图像移动到另一个子文件夹时,我需要根据新名称更改存储中的图像文件名.我怎样才能做到这一点?Firebase元数据具有name属性,但它是readonly属性.
I need to change the file name which is already uploaded in firebase storage. Because, after uploading a image in firebase storage, i save the url in firebase database under a specific child(folder). But when i move the image to another child(folder), i need to change the image file name in storage according to new name. How can i do this? Firebase metadata has a name property, but it is readonly property.
推荐答案
您无法更改已上传到Firebase存储的图像的文件名.你能做的就是
You cannot change the filename of the image that is already uploaded to firebase storage. What you can do is
第1步:从存储设备下载给定的图像
Step 1: download the given image from the storage
第2步:使用 UIImageJPEGRepresentation
方法的 UIImagePNGRepresentation
将UIImage转换为数据.
Step 2: Convert the UIImage to data by using UIImagePNGRepresentation
of UIImageJPEGRepresentation
methods.
第3步:使用所需名称创建引用 Storage.storage().reference().child("DesiredName")
Step 3: Create a reference using the desired name Storage.storage().reference().child("DesiredName")
第4步:将数据上传到Firebase存储 .putData
Step 4: Upload the data to firebase storage .putData
第5步:从Firebase中删除以前上传的数据.
Step 5: Delete the previously uploaded data from firebase.
// Create a reference to the file to delete
let desertRef = storageRef.child("desert.jpg")
// Delete the file
desertRef.delete { error in
if let error = error {
// Uh-oh, an error occurred!
} else {
// File deleted successfully
}
}
这篇关于如何更改已上传的Firebase存储映像文件名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!