I wrote a program to save a series of data in a file and then upload it to firebase. The problem is that when the file is uploaded, the new data replaces the old data and the old data is deleted. My solution to keep the previous data is to first create a file called "file2.txt" and save the data in it. Its volume will reach 50K and then this file will be uploaded and then a file called "file2.txt" will be created and when its volume reaches 50k it will be uploaded and the same process will continue. Now my problem is that I have a problem to make this process of creating the files in order and then upload them. Please guide me with the source code.
String app_name ="app is name :" applicationLabel;
reference= FirebaseStorage.getInstance().getReference().child("Dcument").child("appName");
reference.child("appname.txt").putBytes(app_name.getBytes()).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>()
CodePudding user response:
If you upload the same file name again it will override the previous file so I have followed the below approach
Upload files with different names:
To achieve this I have appended time in millis after file name so you can follow this approach or you can also follow any other approach to make each file name different
String fileName = "file2_" System.currentTimeMillis() ".txt";
You can also create different different directories for each file but you need to manage naming and I would not recommend that approach