Reputation: 165
I have successfully save an image,recorded the sound and save it in Firebase. But the audio file cannot save multiple file, when i try to save another recording, it will replace the old record and only have one file in Firebase. How can i save the new record without replacing the old one in Firebase?
Uri uriAudio = Uri.fromFile(new File(audioFilePath).getAbsoluteFile());
final StorageReference filePath = ref.child("Education/image").child(uriImage.getLastPathSegment());
final StorageReference audioRef = ref.child("Education/audio").child(uriAudio.getLastPathSegment());
// on success upload audio
audioRef.putFile(uriAudio).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(final UploadTask.TaskSnapshot audioSnapshot) {
//upload image
filePath.putFile(uriImage).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(final UploadTask.TaskSnapshot imageSnapshot) {
mProgress.dismiss();
@SuppressWarnings("VisibleForTests") Uri audioUrl= audioSnapshot.getDownloadUrl();
@SuppressWarnings("VisibleForTests") Uri imageUrl= imageSnapshot.getDownloadUrl();
Here is the attachment for audio file in Firebase Storage
Upvotes: 0
Views: 15951
Reputation: 1300
Use from the following two lines to generate UniqueId
Creating an Instance ID:
String id = InstanceID.getInstance(context).getId()
Creating a GUID:
String uniqueID = UUID.randomUUID().toString
Upvotes: 2
Reputation: 165
its work by using timestamp instead of file name, this is my old coding,
audioFilePath =
Environment.getExternalStorageDirectory().getAbsolutePath()
+ "/myaudio.3gp";
Using timestamp is working to save multiple file,
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
audioFilePath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/" + timeStamp;
Upvotes: 0
Reputation: 138824
Yes you can. For this you need to specify each time you upload an audio file a different name for your audio file. If you keep uploading with the same name, your audio will be overridden each time. Unfortunately there is no built-in method to generate a unique audio filename for Firebase Storage (like the push()
method in the Firebase database).
To have globally unique audio filenames, you'll have to generate those names yourself. One way would be to use the Firebase Database's push()
method, but you can also use any other GUID-generator you want.
Upvotes: 0