Third Light Developer Exchange

Code and templating community forum for developers and software integrators

You are not logged in.

#1 2017-12-04 20:07:33

ajpinto
Member
Registered: 2017-11-30
Posts: 11

Listing all files in a folder

How would i go about listing all files in a folder? I can't seem to locate a method for this in the API reference.

Offline

#2 2017-12-05 10:54:44

ben
Third Light Staff
From: Third Light
Registered: 2013-06-06
Posts: 65

Re: Listing all files in a folder

Hi,
You want Files.GetAssetsForParent(...) and possibly also Folders.GetContainersForParent(...)
Ben

Offline

#3 2017-12-05 12:28:21

ajpinto
Member
Registered: 2017-11-30
Posts: 11

Re: Listing all files in a folder

Thanks! Need a little syntax help again if you don't mind.
For Files.GetAssetDetails I have

$details = $myIMSClient->Files_GetAssetDetails(array($file_id, 'options' => array('publishedFiles')));

but it returns a "BAD_INPUT" error

Offline

#4 2017-12-05 13:08:48

ben
Third Light Staff
From: Third Light
Registered: 2013-06-06
Posts: 65

Re: Listing all files in a folder

You probably want:

$details = $myIMSClient->Files_GetAssetDetails(array("assetId" => $file_id, "fields" => array("publishedFiles" => true)));

Ben

Offline

#5 2017-12-05 13:12:58

ajpinto
Member
Registered: 2017-11-30
Posts: 11

Re: Listing all files in a folder

Thank you!

Offline

#6 2017-12-05 13:20:32

ajpinto
Member
Registered: 2017-11-30
Posts: 11

Re: Listing all files in a folder

Sorry to keep bothering you, but if the publishedFiles array is empty, that means the asset has not been published, correct?

Last edited by ajpinto (2017-12-05 13:20:49)

Offline

#7 2017-12-11 17:42:57

ajpinto
Member
Registered: 2017-11-30
Posts: 11

Re: Listing all files in a folder

Hello?

Offline

#8 2017-12-19 12:00:58

ben
Third Light Staff
From: Third Light
Registered: 2013-06-06
Posts: 65

Re: Listing all files in a folder

Hi,
Sorry I missed your last few replies.
The publishedFiles array is populated with information for each "publication" of the asset in question, but only those publications that the current user has access to. i.e. if you can manage all published files, you will see all publications, but if you don't you will only see publications that you have made yourself.

So, the array being empty, is not necessarily an indicator of whether the file has been published, unless the current user can manage all publish files. This permission is controlled by the "Create, edit and delete published files" option in the Downloads section when editing a user.

Best wishes,
Ben

Offline

#9 2017-12-19 14:02:14

ajpinto
Member
Registered: 2017-11-30
Posts: 11

Re: Listing all files in a folder

is using the publishedFiles array the best way to get the URL of the file in question or is there a better method?

Offline

#10 2017-12-28 12:47:45

ajpinto
Member
Registered: 2017-11-30
Posts: 11

Re: Listing all files in a folder

Also, trying to build a drop down box to select a folder. I can get top level folders no problem, but adding recursion to drill down to child folders using 'Folders_GetContainersForParent' has proved to be a challenge. I would like to wrap the child folders into option groups, but I seem to end up with several empty option groups (which i suspect is due to some of the results not being folders), as well as missing folders. Is there a way to exclude results from the array that aren't folders? Do you have an recommendations as to the best method to build what I'm looking for?

Offline

#11 2018-01-02 12:21:55

ben
Third Light Staff
From: Third Light
Registered: 2013-06-06
Posts: 65

Re: Listing all files in a folder

Hi,

re. Folders_GetContainersForParent - this will only return folders. Your empty option groups might be because the parent folders don't contain subfolders. You can check this with the hasChildContainers key in the folder details hash for each folder. If you're still having problems perhaps you could post some code so I can help pinpoint the issue.

There isn't necessarily a right way or wrong way and I'm not entirely sure what your end goal is. All I would say is that it sounds like you're trying to build the entire folder tree into one drop down - this might well be fine if you don't envisage the folder structure being too large, but would be problematic if the structure is deeply nested, or if nodes have many sub-nodes, or both. i.e. you'll potentially have to make many recursive calls to fill the dropdown before you can present anything to your users. An alternative is to only request the sub-containers on demand - e.g. make an Ajax request when a user selects a parent folder from a dropdown, and then dynamically populate another dropdown. There are many many ways of presenting tree structures though, and I have made the assumption you're writing a web based application, so bear this in mind when deciding how to proceed.

Your previous question "is using the publishedFiles array the best way to get the URL of the file in question or is there a better method?" - it's definitely the best way to get the urls of "published" versions of assets within IMS if you already know which asset you're interested in. If you want to list all assets that have been published, filtering out those that haven't, then you probably also want to use the "filterMode":"publishedFiles" in the "options" parameter when getting folder details.

The other thing to mention is that "publishing" is one of two ways of getting URLs to the assets in IMS. Publishing is audited and has a comprehensive user interface when using the IMS web application. Files published in this way have entries in the "publishedFiles" array. But it is also possible to generate "Fetch File URLs" using the API - this is designed much more as a programmatic way of generating URLs and is not audited - i.e. a user (admin or otherwise) can not see whether a Fetch File URL has been generated for a particular file. The two methods are discussed on this page https://www.thirdlight.com/docs/display … on+the+Web and if you wish to pursue the latter option you'll want to look at the API method "Downloads.GetLink" which allows you to create secure urls (i.e. ones which have an authentication token and so can not be tampered with to get different data).


I hope all that helps,
Ben

Offline

Board footer