How can we use WSAPI to create a User along with uploading his Profile Image file?
Let's walk through the process of using WSAPI to create a User along with setting up his username avatar.
Let's examine WSAPI object model to find what needs to be done.
The User endpoint shall be used to create the User, see its methods:
We will scroll down the fields and find all the required attributes. We shall also look for the user's profile image field.
This field refers us to another REST Endpoint, named: ProfileImage. Let's examine that endpoint:
We realize we need to convert the user's profile image file to a 'base64Binary' format.
Let's convert our profile image file to a base64Binary format.
To do that, let's use one (of many) freely available online site:
Here is our user's profile image file:
On the website, let's upload this file and click Convert to Base64:
Now, before we continue, let's test our conversion. So, let's convert it back from the base64Binary back to an image file. To do that , we shall use another freely available website (of many): https://codebeautify.org/base64-to-image-converter
Let's copy the text we have from our first site. Then, in the second site, let's paste the text and click to Generate Image:
Looks good. So we now know our converted base64Binary text from the first site is good.
Let's use WSAPI to create the User and ProfileImage objects. These are two separate objects whereas the User references the ProfileImage. Therefore, we shall first create the ProfileImage object, then use its ObjectID to set it to our new User.
- We'll use the ProfileImage endpoint:
Let's confirm the result and get the ObjectID:
- We'll now create the User and include the ProfileImage field set to the ObjectID we just received:
Let's check the result:
All is looking well.
Let's now check out Agile Central, locate our newly created user and see their profile image:
Bring up the user's profile and...
Our Profile Image is there.