File upload?

202 views
Skip to first unread message

Bennett Brown

unread,
Jun 23, 2014, 3:05:52 PM6/23/14
to canvas-lms...@googlegroups.com

The Files Upload documentation says


Quoting, "Step 1: Telling Canvas about the file upload and getting a token. The first step is to POST to the relevant API endpoint, depending one where you want to create the file. For example, to add a file to a course, you'd POST to /api/v1/courses/:course_id/files."


When I post to this endpoint/api/v1/courses/:course_id/files, I get a 404 error. Am I required to post to a different endpoint? That is suggested in the Folders documentation, which refers us to the Files Upload documentation above.

"Upload a file FoldersController#create_file

POST /api/v1/folders/:folder_id/files

Upload a file to a folder."

The File Upload documentation indicates that parent_folder_path is an argument made in the first POST, with a default folder if unspecified.

Are both of these correct?

Battis, Seth

unread,
Jun 25, 2014, 11:45:20 AM6/25/14
to canvas-lms...@googlegroups.com
Hmm. I would guess not -- I had a bear of a time getting my head around file uploads to Canvas via the API last summer. The result of my work is here (that's a PHP function that uploads a file from a path relative to the script into a course Files hierarchy. A bunch of the CONSTANTS are set in config.inc.php. Looks to me like I set the parent folder as a parameter on the initial request.


— S

Mathematics Dept. Chair • Director of Academic Technology • FIRST Team Mentor
St. Mark's School • 25 Marlboro Rd., Southborough, MA 01772 • stmarksschool.org


--
You received this message because you are subscribed to the Google Groups "Canvas LMS API Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to canvas-lms-api-u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

veronic...@beardon.com

unread,
Jul 22, 2014, 12:48:47 PM7/22/14
to canvas-lms...@googlegroups.com
I've actually been having quite a bit of trouble uploading files through the API as well.  I can get a response status code of 200, and it gives me a status url to poll, but it never seems to complete the request.  Even a few minutes later, it still responds with "pending."


--
You received this message because you are subscribed to the Google Groups "Canvas LMS API Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to canvas-lms-api-users+unsub...@googlegroups.com.

Bennett Brown

unread,
Jul 23, 2014, 10:44:25 PM7/23/14
to canvas-lms...@googlegroups.com, veronic...@beardon.com
Thanks Seth and Veronica. I never succeeded in getting a file uploaded from my machine (even using parent_folder_id as reported by Seth), but did succeed by uploading the file to a web server and then uploading to Canvas using from that URL.

While trying to use the upload-from-local-machine method described in the API documentation, I would get an error like one of the two listed below. I think these were returned in response to the second step's unauthenticated post, but I'd have to dig back into it to be sure. At the time, I decided that the explanation was that Canvas was expecting the header fields in a particular order (which is hinted at in the Canvas API documentation that says the fields provided in response to the first post must be returned in the second post without alteration, except that one additional field should be added "at the end"), that this was in violation of HTTP standards, and that the requests-toolbelt package, a Python extension to the Python requests package I was using, was the only way I could force a particular order to the fields in the post request. Before exhausting my option (or succeeding) with that package, though, I found success with the upload from a public URL method.

<Error><Code>AccessDenied</Code><Message>Query-string authentication requires the Signature, Expires and AWSAccessKeyId parameters</Message><RequestId>46BF1...A9E3</RequestId><HostId>xU4jkA...bZ23w=</HostId></Error>

or

<Error><Code>InvalidArgument</Code><Message>Bucket POST must contain a field named \'key\'.  If it is specified, please check the order of the fields.</Message><ArgumentValue></ArgumentValue><ArgumentName>key</ArgumentName><RequestId>F56E...1A5B</RequestId><HostId>8p7hwWEW...VvZj</HostId></Error>

veronic...@beardon.com

unread,
Jul 28, 2014, 2:12:06 PM7/28/14
to canvas-lms...@googlegroups.com, veronic...@beardon.com
I'm glad you got it to work!  I actually haven't been able to upload anything using either method listed in the API docs.  Whenever I try to upload something via URL, I always get a response of "pending" that never changes to "ready" or "errored," even when I poll the status URL several minutes after the request was made.
Reply all
Reply to author
Forward
0 new messages