Uploading files to a user's profile

Jump to solution
Community Novice

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

Labels (1)
1 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>"

View solution in original post