Unable to download file from User Table


Im trying to use file service to upload and download file which are specific to a single user in my table.
I’m using the following file for upload

                            NSString *imgFileName = [NSString stringWithFormat:@"img/%0.0f.jpeg", [[NSDate date]timeIntervalSince1970]];
                            NSURL *url = [NSURL URLWithString:fbPic];
                            NSData *imageData = [[NSData alloc]initWithContentsOfURL:url];
                            [backendless.fileService upload:imgFileName content:imageData response:^(BackendlessFile *uploadFile) {
                                [user setProperty:@"imageURL" object:uploadFile];
                                NSLog(@"File Uploaded successfully %@", uploadFile);
                                [backendless.userService update:user];
                            } error:^(Fault *fault1) {
                                NSLog(@"file upload fault %@", fault1);

File uploads successfully to my user table and is stored as shown:


In the next View Controller, I’m trying to download this file using the following code:

    BackendlessUser *user = [backendless.userService currentUser];
    NSString *objectID = [user getProperty:@"objectId"];
    [backendless.userService findById:objectID response:^(BackendlessUser *user) {
        NSLog(@"User Details %@", [user getProperty:@"deviceId"]);

        self.nameLabel.text = [user getProperty:@"name"];

        imageURL = [user getProperty:@"imageURL"];
        NSLog(@"image url is %@", imageURL);
        NSURL *url = [NSURL URLWithString:imageURL];
        NSData *urlData = [NSData dataWithContentsOfURL:url];
        self.personalPic.image = [UIImage imageWithData:urlData];
    } error:^(Fault *fault) {
         NSLog(@"Error retrieving user details: %@", fault);

The log prints out the following:

image url is <BackendlessFile> -> fileURL: https://api.backendless.com/8d33a918-3dd1-85bd-ffd0-10b7f2458900/v1/files/img/1459791481.jpeg

But I get a crash on line 12:

-[BackendlessFile length]: unrecognized selector sent to instance 0x7fc60a55c410
 *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[BackendlessFile length]: unrecognized selector sent to instance 0x7fc60a55c410'

How do I download a file? I know its something to do with the URL call. And the URL string seems to have other information attached to it “<BackendlessFile> -> fileURL:”
How do I get just the URL so that I can download the file…



Hi Mike,

See lines 5 & 6 in the first part of the code:

[backendless.fileService upload:imgFileName content:imageData response:^(BackendlessFile *uploadFile) {
[user setProperty:@"imageURL" object:uploadFile];

So, imageURL property contains BackendlessFile object, not an url, and a line 9 of the second part of the code should be like this:

imageURL = [user getProperty:@"imageURL"].fileURL;


Did Slava’s response solve the problem for you?