I am downloading and uploading the name and URL of audios from firebase storage. I downloaded the URL and name successfully but this is not uploading to the firebase database
data downloading and uploading
StorageReference reference = storage.getReference().child("Ringtone");
reference.listAll().addOnSuccessListener(listResult -> {
Log.d("Tag","reference listed");
for(StorageReference item:listResult.getItems()){
Task<Uri> downloadUrlTask = item.getDownloadUrl();
Task<StorageMetadata> downloadNameTask = item.getMetadata();
Tasks.whenAll(downloadNameTask,downloadUrlTask).addOnSuccessListener(unused -> {
Methods methods = new Methods();
methods.firebse_ring_upload(downloadNameTask.getResult().getName(),downloadUrlTask.getResult());
});
}
});
Method class
package com.example.alarm.Methods;
import android.net.Uri;
import android.util.Log;
import com.example.alarm.Models.RingtoneModel;
import com.google.firebase.database.FirebaseDatabase;
public class Methods {
FirebaseDatabase database = FirebaseDatabase.getInstance();
public void firebse_ring_upload(String songName, Uri uri){
RingtoneModel ringtoneModel = new RingtoneModel(songName,uri.toString());
database.getReference().child("Ringtones_Room").child(songName.replace(" ","").replaceAll("[\\W+]","")).setValue(ringtoneModel);
}
}
RingtoneModel (POJO class)
package com.example.alarm.Models;
import android.net.Uri;
public class RingtoneModel {
String SongName;
String uri;
public RingtoneModel(String songName, String uri) {
SongName = songName;
this.uri = uri;
}
public RingtoneModel(){}
public String getSongName() {
return SongName;
}
public void setSongName(String songName) {
SongName = songName;
}
public String getUri() {
return uri;
}
public void setUri(Uri uri) {
this.uri = uri.toString();
}
}
previously this was showing StackOverflow error
because I was trying to save URI in the database. but this should work now. This not showing me any type of error also.
if any other info required. comment down
Edit
I updated my method just like this: (in method class
)
public void firebse_ring_upload(String songName, Uri uri){
RingtoneModel ringtoneModel = new RingtoneModel(songName,uri.toString());
database.getReference("https://alarm-sachinbudak-default-rtdb.asia-southeast1.firebasedatabase.app/").child("Ringtones_Room").child(songName.replaceAll("[\\W+]","")).setValue(ringtoneModel);
}
but this is giving me a new error:
com.google.firebase.database.DatabaseException: Invalid Firebase Database path: https://alarm-sachinbudak-default-rtdb.asia-southeast1.firebasedatabase.app/. Firebase Database paths must not contain '.', '#', '$', '[', or ']'
at com.google.firebase.database.core.utilities.Validation.validatePathString(Validation.java:45)
at com.google.firebase.database.core.utilities.Validation.validateRootPathString(Validation.java:58)
at com.google.firebase.database.FirebaseDatabase.getReference(FirebaseDatabase.java:181)
at com.example.alarm.Methods.Methods.firebse_ring_upload(Methods.java:14)
at com.example.alarm.MainActivity.lambda$onCreate$3(MainActivity.java:85)