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.
Found this content helpful? Log in or sign up to leave a like!
Hello all,
Running into a bit of a weird roadblock here using the Canvas File Upload API to upload a file to a course via API. I've followed the documentation here: Uploading Files - Canvas LMS REST API Documentation
I think I've followed the directions correctly. I'm seeing the expected response after step 1.
Array
(
[upload_url] => https://instructure-uploads.s3.amazonaws.com/
[upload_params] => Array
(
[AWSAccessKeyId] => RANDOMLETTERSANDNUMBERS
[Filename] => test.txt
[key] => account_101010101010101/attachments/10101010101/test.txt
[acl] => private
[Policy] => BUNCHOFCHARACTERS
[Signature] => MORECHARACTERS
[success_action_redirect] => https://our.test.instructure.com/api/v1/files/10101010101/create_success?uuid=abc123
[content-type] => text/plain
)
[file_param] => file
)
I used the [upload_params] array to POST to [upload_url] (and I also added the file=@test.txt) based on the documentation; but instead of getting the expected 301 with a Location parameter and success url, I am getting a 302.
This 302 has 2 Location headers, both if which are urls to the test.txt file, only it doesn't match what I tried to upload, it's just a text file that says @test.txt. Something is not right here.
It seems that my local file, test.txt, which is in the same directory as the script I'm running, is not making it to Amazon...or...something like that? Is it possible my using Vagrant as a dev environment would cause this issue? I'm trying to do this in our test instance of Canvas, is it possible this could be the reason for the strange behavior? Am I just missing something terribly obvious and I've been staring at this too long?
Solved! Go to Solution.
@marc_mestre I recently posted source code demonstrating a possible implementation of the API in .NET
Today I added a class to that project specifically showing how to execute steps associated with "Uploading via POST" found here: Uploading Files - Uploading via POST
I don't know what language you are using, but you sould be able to follow the flow of the logic.
The original post with directions to the source code is here:
Take a look at the file: clsFileUpload.cs
There are three regions containing code for the three phases of the file upload process.
I hope this helps.
@marc_mestre notice that the documentation says you will receive a 3xx redirect:
"If Step 2 is successful, the response will be a 3XX redirect with a Location header set as normal".
If you are receiving a 302, that should be fine.
Are you completing the 3rd step: confirm the upload success?
Thanks for the reply @garth
I've tried the third step 2 ways!
Once with stream_context_create (PHP). This throws an error for both Location headers in the 302. One is a 400 bad request. The other is a 422 Unprocessable entity.
I've also tried with curl, which does not seem to throw any errors. However, the file that gets confirmed is not the file I'm attempting to upload. I have a test.txt file with some nonsense in it, but what ends up in Canvas is a text file that simply says '@test.txt' and nothing else.
It has been a while since I worked on file uploads, but I do have existing code I can test with.
I'm slammed right now, but will try to find some time to step back through it and share my results with you.
@marc_mestre I recently posted source code demonstrating a possible implementation of the API in .NET
Today I added a class to that project specifically showing how to execute steps associated with "Uploading via POST" found here: Uploading Files - Uploading via POST
I don't know what language you are using, but you sould be able to follow the flow of the logic.
The original post with directions to the source code is here:
Take a look at the file: clsFileUpload.cs
There are three regions containing code for the three phases of the file upload process.
I hope this helps.
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