@ronald28659 There are new methods for listing files and folders.
They are: listFolders(filters, sort, pagination), listFiles(filters, sort, pagination);
The example code on the API docs is a little bit wrong, as it omits the parameters as optional, and they don’t appear to be optional, whether by design or bug (the intention may have been for them to be optional). I got red squigglies when I copy/pasted the example code, so I had to add in empty objects for the params.
You can use two new methods listFolders and listFiles to list the directories and files at each level. If the term “parentFolderId” is a little bit confusing, you can think of it as “the enclosing folder”
Here’s an example.
(Top level folders have a parentFolderId named “media-root”)
In my media manager, I have the following directory/file structure. Directories in blue, files in red:
(media-root)/ Plants/Large / 0001_s.jpg
(media-root)/ Plants/Large / 0001_2_s.jpg
… etc …
The complaint has been that you’ve never been able programmatically look up either the Wix filename, the original filename, or the directory structure or contents once the file was already in the Media Manager. Now you can:
First, I got the folders in the media root (you can do this by either passing an empty filter, or pass “media-root” as the parent folder ID).
const filters = {};
const sort = { order : ‘asc’ , field : ‘originalFileName’ };
const pagination = { limit : 100 };
return mediaManager . listFolders ( filters , sort , pagination ). then (( rootFolders ) => {
…
This returned all of my top level folders. One of which is Plants:
folderId : “25334a1d305d44888408d1f82c6e0387”
folderName : “Plants”
parentFolderId : “media-root”
Next, I did another listFolders, this time passing the Plants folderID:
const filters = {
parentFolderId : “25334a1d305d44888408d1f82c6e0387”
};
const sort = { order : ‘asc’ , field : ‘originalFileName’ };
const pagination = { limit : 100 };
return mediaManager . listFolders ( filters , sort , pagination ). then (( plant Folders ) => {
…
This returned the “Large” folder underneath the Plants folder:
folderId : “c3aa8f2936804701b12fee15ce90278b”
folderName : “Large”
parentFolderId : “25334a1d305d44888408d1f82c6e0387”
I have files (no folders) underneath “Large”, so I got them by using listFiles:
const filters = {
parentFolderId : “c3aa8f2936804701b12fee15ce90278b”
};
const sort = { order : ‘asc’ , field : ‘originalFileName’ };
const pagination = { limit : 100 };
return mediaManager . listFiles ( filters , sort , pagination ). then (( largeFiles ) => {
…
This returned the first 100 files in that directory. Here are the two I mentioned above (0001_s.jpg, 0001_2_s.jpg). There are a bunch of other properties, but I’ve only included the properties that are interesting to this conversation:
fileName : “c565a4_470557f697d34089b28ac2b5a8033361~mv2.jpg”
fileUrl : “wix:image://v1/c565a4_470557f697d34089b28ac2b5a8033361~mv2.jpg/0001_s.jpg#originWidth=600&originHeight=400”
originalFileName : “0001_s.jpg”
parentFolderId : “c3aa8f2936804701b12fee15ce90278b”
fileName : “c565a4_46b6cefb5ef74892930c5967e0674109~mv2.jpg”
fileUrl : “wix:image://v1/c565a4_46b6cefb5ef74892930c5967e0674109~mv2.jpg/0001_2_s.jpg#originWidth=600&originHeight=400”
originalFileName : “0001_2_s.jpg”
parentFolderId : “c3aa8f2936804701b12fee15ce90278b”
These two new Media Manager API methods give me more or less complete control over viewing the contents of my directory structure. I still don’t see a way to move, rename, or remove files using the API. I can only do read only operations.
In another Forum thread on this subject, someone was complaining about not being able to be GDPR compliant, because they cannot programmatically wipe out Visitor files. So it appears that might still be a hole in the API. But for my immediate need, just being able to traverse my directory tree and look up Wix’s filenames for my own human readable filenames is HUGE.