I am using firebase storage for saving images, when I retrieve them on application, files are not sorting alphabetically.
Firebase sorting files by date time, first upload showing on first then second.
I have a lot of files and cannot upload these files one by one.
Is there any way to sort files by alphabetically.
like
001.png
002.png
003.png
004.png
005.png
…
`
private void saveAllSigns() {
showDialog();
for (int i = 0; i < SignNameList.length; i++) {
StorageReference storageReference = FirebaseStorage.getInstance().getReference().child(SignNameList[i]);
int finalI1 = i;
storageReference.listAll().addOnSuccessListener(new OnSuccessListener<ListResult>() {
@Override
public void onSuccess(ListResult listResult) {
List<StorageReference> list = listResult.getItems();
for (StorageReference str : list) {
long SIZE = 1024 * 1024;
str.getBytes(SIZE).addOnSuccessListener(new OnSuccessListener<byte[]>() {
@Override
public void onSuccess(byte[] bytes) {
saveData(bytes, str.getName(), finalI1);
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Log.d("SlashLog", "Firebase Exception: " + e.getMessage());
}
`
looking for solution
2
Answers
thanks for answer but error has resolved from here in data base helper ORDER BY ASC
According to the Firebase documentation given by frank,
listAll()
call should be returning the files in lexicographical order.Seems order of the files in the list is being changed by the
for
loop that iterates through the list. Maybe you should try sorting the list before iterating through it.listAll()
method is being called inside afor
loop that iterates over theSignNameList
. If the elements in the SignNameList array are in chronological order, then thelistAll()
method will return the files in chronological order as well.As also mentioned here, Consistency of the result is not guaranteed if objects are inserted or removed while this operation is executing.