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.
1 Answers
2
votes
You cannot change the filename of the image that is already uploaded to firebase storage. What you can do is
Step 1: download the given image from the storage
Step 2: Convert the UIImage to data by using UIImagePNGRepresentation
of UIImageJPEGRepresentation
methods.
Step 3: Create a reference using the desired name Storage.storage().reference().child("DesiredName")
Step 4: Upload the data to firebase storage .putData
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
}
}