I am trying to rename a folder in Firebase Storage and have no idea on how to do it. I have tried searching online where most of them say I have to get the file, write the file in the new path and delete the old file.
I tried this method
StorageReference storageReference = FirebaseStorage.getInstance().getReference();
StorageReference sourceStorage = storageReference.child(userEmail + "/" + foodName + "/" + foodName + ".jpg");
StorageReference destinationStorage = storageReference.child(userEmail + "/" + userInput + "/" + userInput + ".jpg");
// Example:
// The path for sourceStorage is "abc@gmail.com/Rice/Rice.jpg"
// The path for destinationStorage is "abc@gmail.com/White Rice/White Rice.jpg"
sourceStorage.getDownloadUrl.addOnSuccessListener(new OnSuccessListener<Uri>() {
@Override
public void onSuccess(Uri uri) {
destinationStorage.putFile(uri);
sourceStorage.delete():
}
});
I have tried the above code but it does not put the image into the destination path and the new path does not exist in firebase. Am I doing something wrong as I have no idea how to get the image to another folder if the user change the name. Thank you for your time.