The Instructure Community will enter a read-only state on November 22, 2025 as we prepare to migrate to our new Community platform in early December. Read our blog post for more info about this change.
Has anyone successfully uploaded a file to another user's profile?
I"m trying to upload each user's ID card picture to their profile, but I've hit some snags. When I push to /api/v1/users/self/files where is the file going to exactly?
According to the API
Passing a user_id of
selfis an easy shortcut to specify the current user.
How do I know what the current user is when using the URL above? My guess is its uploaded to the user who owns the API key, but I wasn't the who created the key, so I don't know where our key was created from.
Some notes:
* I'm uploading using an URL. We're a Banner school and the pictures are hosted in Banner as blobs.
* If I try to upload to a user's URL (/api/v1/users/<user_id>/files) I get a permission error. Even using my user's ID.
* I'm using a modified version of this script.
I don't want 3000 images hanging out in some user's profile or in some random S3 repo somewhere. Each user should have their profile picture in their file storage.
I should mention, I'm using curl for testing. I have not actually run my script. I want to make sure all my API calls are good. Thinking about this more, it would seem the API is meant for internal use. Where self would be the authenticated user, which in this case would be my API key. Perhaps, this can't be done the way I want.
Solved! Go to Solution.
Thank you, Colin!
Huge help! as_user_id was the way to go. Below is the curl I used for testing. Worked like a charm.
For those searching in the future, here's the link to the docs.
curl 'https://<DOMAIN>.instructure.com/api/v1/users/self/files' \
-F 'url=<URL_TO_THE_FILE>' \
-F 'name=profile_pic.gif' \
-F 'size=3000' \
-F 'content_type=image/gif' \
-F 'parent_folder_path=profile pictures' \
-F 'as_user_id=sis_user_id:<THE_ID_OF_THE_USER>' \
-H "Authorization: Bearer <API_KEY>"
@wlehnertz , given the technical nature of this question I'm going to share it with the https://community.canvaslms.com/groups/canvas-developers?sr=search&searchId=bba71d02-1703-4f76-ba87-... group in the Community. They are the ones that do a lot of this type of back-end programming in Canvas and can hopefully help answer your question.
Hi William --
You're on the right track with the 'self' parameter, but you also need to masquerade as each user by including the 'as_user_id' parameter in the upload request. In order for that to work, your API token will need to have the "Become other users" permission -- whoever created the API token for you should be able to set that up.
--Colin
Thank you, Colin!
Huge help! as_user_id was the way to go. Below is the curl I used for testing. Worked like a charm.
For those searching in the future, here's the link to the docs.
curl 'https://<DOMAIN>.instructure.com/api/v1/users/self/files' \
-F 'url=<URL_TO_THE_FILE>' \
-F 'name=profile_pic.gif' \
-F 'size=3000' \
-F 'content_type=image/gif' \
-F 'parent_folder_path=profile pictures' \
-F 'as_user_id=sis_user_id:<THE_ID_OF_THE_USER>' \
-H "Authorization: Bearer <API_KEY>"
Community helpTo interact with Panda Bot, our automated chatbot, you need to sign up or log in:
Sign inTo interact with Panda Bot, our automated chatbot, you need to sign up or log in:
Sign in
This discussion post is outdated and has been archived. Please use the Community question forums and official documentation for the most current and accurate information.