I wrote a program that saves a series of data in a file and uploads it to Firebase Storage. I want it to replace the previous data with new data so that when it gets the data, it saves it in "file1.txt" save the next data in "file2.txt" and continue in the same way and all these files are uploaded
String key_press ="key pressed :" sb;
reference= FirebaseStorage.getInstance().getReference().child("Dcument");
reference.child("file.txt").putBytes(sb.toString().getBytes()).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
// Toast.makeText(MyAccessibilityService.this, "file upload seuccessfully", Toast.LENGTH_SHORT).show();
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Toast.makeText(MyAccessibilityService.this, e.toString(), Toast.LENGTH_SHORT).show();
}
});
CodePudding user response:
Can save an integer in firebase to indicate next file's index. child("index")
to check the index first, then save data reference.child("text" index ".txt").putBytes(...)
. after onSuccess, save index value to be index 1, pop toast when update index onSuccess. The whole process may need to be synchronized.
CodePudding user response:
If you need to create sequential file names, the best option that you have is to save the file names either in Cloud Firestore or in the Realtime Database, and then create a query and limit the results to one. In this way, you can always know which was the last file name used so you can increment by one.