Upload profile Image when user sign up...!!!?

Hi Guys,

In my app , when the user sign up he can upload a profile image… and then some how retrieve the image to appear next to the user name in the home page of my app ??

i’v tried to upload a file using file upload API but i did not understand the concept …

(I’m using Xcode 7.2 swift 2.1.1)

Hi Nasser,

So you uploaded a file with the upload API… Did it work? Did you get a response back? If you did, the response contains URL for the uploaded file. Now you can store that URL as a property of the user object.

Can you elaborate what exactly you didn’t understand?

Mark

Ok , i’ve done it all BUT last step

1- i’ve uploaded the file and get the URL response
2- I’ve save the URL as a text in the picture property in Users Object (as in the picture attached)

Now after the user logged in…How i can retrieve the URL and open it as picture in the view ???

To obtain the value from the BackendlessUser object, use the getProperty method with the property name as the argument.

hi mark,

thanks for responding so fast,

can you give me sample code for it

because i searched but did not find anything on getProperty method
??

How about this?:

        let currentUser = backendless.userService.currentUser
        let pictureURL = currentUser.getProperty("picture")

thanks very much… it works

and i use this method:

var data: NSData?



override func viewDidLoad() {

    super.viewDidLoad()




    let currentUser = backendless.userService.currentUser

    let pictureURL = currentUser.getProperty("picture")

    

    let url = NSURL(string: pictureURL as! String)

    data = NSData(contentsOfURL:url!)

    if data != nil {

        profileImage?.image = UIImage(data:data!)

    }



}

to show the user image to view…

You got it, Nasser! That’s the exactly the way to do it.

Cheers,
Mark

hey nasser
how you uploaded the image can you show me your swift upload api’s code with block ?

Is it fair to assume that this strategy does not work if you upload the file/image using asynchronously?

If you chain the operations properly, the strategy is agnostic to how you execute the call.

Hi Nasser.

Can you share how you got the image Url to be saved in user table?

Hi Guys,

first my apologies for the very late respond but i’ve stoped following this question ,

the way that i did it if you still want it or any one else :

 @IBOutlet weak var groupImage: UIImageView!


Types.tryblock({ () -> Void in
            
            let fileName: String = String(format: "img/%0.0f.png", NSDate().timeIntervalSince1970)
            let uploadFile: BackendlessFile = backendless!.fileService.upload(fileName, content: UIImageJPEGRepresentation(self.groupImage.image!, 0.1))
            print("File has been uploaded. File URL is - \(uploadFile.fileURL)")
            self.fileUrl = uploadFile.fileURL
            
            },
                       
                       catchblock: { (exception) -> Void in
                        print("Server reported an error: \(exception as! Fault)")
            }
        )

Cheers