We are using filepicker.io to load multiple files into our Ruby-based web application. The file list returned from filepicker.io is in the order in which the uploads completed. Is there a way to get the returned file list to be in the order the files appeared in the filepicker.io interface. We are trying to prevent the users from being confused, and would like to present them the files in the order they appeared in the filepicker.io interface.
Asked
Active
Viewed 133 times
1 Answers
1
Filepicker has no sort function but since you get Array of objects you can sort it by some value.
Local files typically are sorted by filename. Example filepicker array:
var blobArray = [
{
"url":"https://www.filepicker.io/api/file/tycOAXjbQU2DJR4WGhGl",
"filename":"facebook_photo.jpg",
"mimetype":"image/jpeg",
"isWriteable":true
},
{
"url":"https://www.filepicker.io/api/file/jOBXIKBQtukNEBJFDRjg",
"filename":"2.jpg",
"mimetype":"image/jpeg",
"isWriteable":true},
{
"url":"https://www.filepicker.io/api/file/sjoVCCVTT3euKVpzBL5p",
"filename":"xxx.jpg",
"mimetype":"image/jpeg",
"isWriteable":true
},
{
"url":"https://www.filepicker.io/api/file/qATXanFXRjSkcG0onEee",
"filename":"xx.jpg
.jpg","mimetype":"image/jpeg","isWriteable": true
},
{
"url":"https://www.filepicker.io/api/file/KyAh8HNSoWZZOQeAs2mR",
"filename":"3.jpg",
"mimetype":"image/jpeg",
"isWriteable":true
},
{
"url":"https://www.filepicker.io/api/file/x3DpwRauDiAMEeZwj2wT",
"filename":"4.png
.jpg","mimetype":"image/jpeg",
"isWriteable": true
}
];
Sort by filename:
blobArray.sort(function(a, b){
var filenameA = a.filename.toLowerCase(),
filenameB = b.filename.toLowerCase();
if (filenameA < filenameB) //sort string ascending
return -1
if (filenameA > filenameB)
return 1
return 0 //default return value (no sorting)
});

krystiangw
- 529
- 5
- 14