cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
bniessen
New Member

Adding, approving and locking avatars via the API

Jump to solution

Hi Community,

I am posting as the API documentation doesn't mention the 'approve' and 'lock' functionality that the admin web interface has for student avatars.

My desired outcome is to modify student avatars and lock them so they cannot be changed by students - I need to do this from the API.

I would also like the avatar image source to remain private and am wondering about the following:

     - Does Canvas do any caching for the avatar images or are they loaded from the URL each time?

     - If I host the avatar images on the school campus, and only allow access from the school network, how gracefully will the avatar image fail outside of the school network?

Thanks,

Brad

1 Solution
kevin
Instructure
Instructure

It isn't currently possible to approve or lock user avatars via the Canvas API.

One way to keep the avatar images private is to upload them into Canvas rather than linking to an external URL. A sample of this being done can be seen in a community script in Github at canvas-contrib/bulk_upload_avatars.py at master · kajigga/canvas-contrib · GitHub.

Canvas doesn't otherwise do any caching of these avatar images. If the image is only available on the local network then it would display as a broken image outside if the network.

View solution in original post

11 Replies
glparker
Community Champion

     - If I host the avatar images on the school campus, and only allow access from the school network, how gracefully will the avatar image fail outside of the school network?

One way to test for this would be to host an image somewhere at a URL you control, load that image into Canvas, then delete the image at that URL.   You'll see what it would look like to Canvas is the image was blocked by your school firewalls.

Glen

bniessen
New Member

I realise I can test this myself, but was looking for advice from administrators with experience in this scenario before I devoted any time to implementing a solution. Regardless, thank you for your response Glen.

Brad

jordan
Instructure
Instructure

Deactivated user​ do you have someone on your team that could offer some direction to  @bniessen ​?

kevin
Instructure
Instructure

It isn't currently possible to approve or lock user avatars via the Canvas API.

One way to keep the avatar images private is to upload them into Canvas rather than linking to an external URL. A sample of this being done can be seen in a community script in Github at canvas-contrib/bulk_upload_avatars.py at master · kajigga/canvas-contrib · GitHub.

Canvas doesn't otherwise do any caching of these avatar images. If the image is only available on the local network then it would display as a broken image outside if the network.

The snippet at canvas-contrib/bulk_upload_avatars.py at master · kajigga/canvas-contrib · GitHub does not seem to work.

Still looking for a solution to my issue.

For now I will try and contact the author of the Python snippet.

Brad

I have been able to update the python script and get it to work. Short version: add "sis_user_id:" before user_id in the API calls. I can paste the script if anyone wants.

However, now I've hit a new problem: after upload 65 images I get "[(u'message', u'file size exceeds quota')]". They're all pretty small images, ~60kB in size.

I have another version of the Python script which I have modified to work a little bit better.

PM me and I can send it to you if you like.

Brad

I worked out the problem, some users were over quota. If I temporarily increase the quota then the script works. Some of them had 1GB+ when their quota was 50MB ...

Also there is a bit of a delay in the API. Once you upload the image, the avatars API call doesn't immediately return the new picture as an option. I've solved this by splitting the main loop and running the avatar API call part after the upload part.

Hi Brad

would you you be able to send me the script please it has been driving me crazy trying to get it to work

0 Kudos

 @helmut_h_wirth  has posted this question in three places, so please post replies to Assign Profile Pictures . Thanks!

0 Kudos

Hi Brad, 

can you please provide new version of your script?

im getting the error -

ConnectionError: HTTPConnectionPool(host='http', port=80): Max retries exceeded with url: //name.test.instructure.com//api/v1/users/self/files (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x00000195F5962F98>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed'))

thank you!

Olga

0 Kudos