AnsweredAssumed Answered

REST API - Amazon S3 file upload confirmation problems?

Question asked by Jeremy Clarke on Jul 27, 2016

Hi, hope this is the correct place to ask for help! I've been trying for the last couple of days to upload a file with C# using the Canvas API. After some time battling with REST libraries and such, I'm now fairly certain that what I'm doing is correct, following these steps: Uploading Files - Canvas LMS REST API Documentation

 

"Step 1: Telling Canvas about the file upload and getting a token"

This works fine, I send a request to Canvas and get the following response:

{   "upload_url": "https://instructure-uploads-eu.s3-eu-west-1.amazonaws.com/",   "upload_params": {     "AWSAccessKeyId": ".......................",     "Filename": "TEST.pdf",     "key": "account_18480000000000001/attachments/2991455/TEST.pdf",     "acl": "private",     "Policy": "..........................",     "Signature": "...........................",     "success_action_redirect": "https://.....canvas url....../api/v1/files/2991455/create_success?quota_exemption=1a9a1bb7a6&uuid=.............................",     "content-type": "application/pdf"   },   "file_param": "file" }

 

"Step 2: Upload the file data to the URL given in the previous response"

This is where things get a bit weird.

I'm using the multipart form code as given in this tutorial: Multipart Form Post in C#  - Brian Grinstead

I replaced the Dictionary with a List so that the parameters are guaranteed to be added in the correct order.

 

However, when I send my request to Amazon web services, instead of getting a response like

HTTP/1.1 301 Moved Permanently
Location: https://<canvas>/api/v1/s3_success/1234?uuid=ABCDE

 

I get status code 200 'OK', with the following headers:

Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, Authorization, Accept-Encoding Access-Control-Allow-Methods: POST, PUT, DELETE, GET, OPTIONS Access-Control-Allow-Origin: * Access-Control-Request-Method: * Status: 200 OK Vary: Accept-Encoding X-Canvas-Meta: q=1139;a=1;g=5Ttwclj1ab2PNhMTWIZMMiylCPoOoff99sh8cXVY;s=1848;c=cluster15;z=eu-west-1a;o=files;n=api_create_success;b=1005488;m=1005488;u=0.12;y=0.00;d=0.04; X-Content-Type-Options: nosniff X-Frame-Options: SAMEORIGIN X-Request-Context-Id: ea77d70b-5671-4cd0-ada9-1c957e8e2a73 X-Request-Processor: a2666ab X-Runtime: 0.221079 X-UA-Compatible: IE=Edge,chrome=1 X-XSS-Protection: 1; mode=block Connection: keep-alive Content-Length: 562 Cache-Control: max-age=0, private, must-revalidate Content-Type: application/json; charset=utf-8 Date: Thu, 28 Jul 2016 03:52:09 GMT ETag: "d4a2e9ce67f15244e424ae9a594909fe" P3P: CP="None, see http://www.instructure.com/privacy-policy" Set-Cookie: _csrf_token=.................; path=/; secure Server: Apache

 

and the following JSON content:

{"id":2991455,"folder_id":218826,"display_name":"TEST.pdf","filename":"TEST.pdf","content-type":"application/pdf","url":"https://......canvas url....../files/2991455/download?download_frd=1\u0026verifier=..............","size":410908,"created_at":"2016-07-28T03:52:08Z","updated_at":"2016-07-28T03:52:09Z","unlock_at":null,"locked":false,"hidden":false,"lock_at":null,"hidden_for_user":false,"thumbnail_url":null,"modified_at":"2016-07-28T03:52:08Z","locked_for_user":false,"preview_url":"/users/71907/files/2991455/file_preview?annotate=0"}

 

This doesn't seem to be any kind of error, but it is not the same result as given by the API documentation. I don't know how to proceed to "Step 3: Confirm the upload's success" when I have not been given a location header. I guessed that the success_action_redirect URL from Step 1 might have been able to help, but submitting there just gives a Bad Request error.

 

Any help would be hugely appreciated, thank you!

Outcomes