How can I list file directory in IOS

Types.tryblock({ () -> Void in

let result = self.backendless.file.listing("/users", pattern:"*.jpeg", recursive:true)
let files = result.getCurrentPage()
for file in files {
if file.name == String(self.backendless.userService.currentUser.getProperty(“objectId”))
{
self.profilephoto.image = file as! UIImage
}
}},
catchblock: { (exception) -> Void in
print(“Server reported an error: (exception as! Fault)”)
})
Hi,
I want to get file directory. How can I do ? And How can I get current user properties ?

Hi Alican,

Here are examples of listing method of FileService class:

    func getListingSync() {
        
        Types.tryblock({ () -> Void in
            
            let result = self.backendless.file.listing("/doc", pattern:"*.txt", recursive:false)
            let files = result.getCurrentPage()
            print("LISTING (SYNC):")
            for file in files as! [BEFileInfo] {
                print("\(file.name) [\(file.publicUrl)]")
            }
            },
            catchblock: { (exception) -> Void in
                print("Server reported an error: \(exception as! Fault)")
            }
        )
    }
    
    func getListingAsync() {
        
        self.backendless.file.listing("/doc", pattern:"*.txt", recursive:false,
            response: { ( result : BackendlessCollection!) -> () in
                let files = result.getCurrentPage()
                print("LISTING (ASYNC):")
                for file in files as! [BEFileInfo]  {
                    print("\(file.name) [\(file.publicUrl)]")
                }
            },
            error: { ( fault : Fault!) -> () in
                print("Server reported an error: \(fault)")
            }
        )
    }

As you can see, you get the array of BEFileInfo objects - and then you can use the properties of BEFileInfo object.

Regards,
Slava

I tried it but I can’t do this. How can I do ?http://support.backendless.com/public/attachments/2734b653e429ee1e850162ebf2b23a33.png</img>

Alican, ‘file’ variable is BEFileInfo object (information about file) - it cannot be cast to UIImage object!

For casting file context to UIImage you need maybe to download this file using its URL, that is in file.publicUrl (you download the file using the nature iOS API).

Hi Alican,

The cause of crash is fixed - you can get the fixed lib from github.

Regards,
Slava

http://support.backendless.com/public/attachments/2b97fe1de82e97b0a4cc12240f36e327.png</img>

I understand it, I will do this.but I can’t access file’s property. Why ?

Please update lib from github - the class mapping was changed.

Thank you very much for your help Vyacheslav Vdovichehnko.