Canvas File Upload API POST and Amazon

Jump to solution
marc_mestre
Community Novice

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?

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

View solution in original post