Backendless Support
 
Answered

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)

Leave a Comment

Comments (12)

photo
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

photo
1

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 ???

photo
1

hey nasser

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

photo
1

Hi Nasser.

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

photo
1

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 :

  1. @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

photo
photo
1

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

photo
1

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

??

photo
2

How about this?:

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

photo
2

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....

photo
1

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

Cheers,

Mark

photo
1

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

photo
1

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

photo