cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
raodm
Community Participant

Uploading file as assignment submission via API

Hello,

I am working on an LTI integration with Canvas. I am trying to upload file(s) (say hello.txt) as assignment submission. However, I get the error message shown below:

curl 'https://miamioh.test.instructure.com/api/v1/courses/30928/assignments/317351/submissions/self/files' -F 'name=hello.c' -F 'size=81' -F 'content_type=text/x-c++src' -H 'Authorization: Bearer Token' 
{"errors":[{"message":"The specified resource does not exist."}],"error_report_id":6979213040}

I have verified the path (course ID, assignment ID etc.) and token. I tried with different assignments but no luck. The Canvas-web application seems to be able to upload files to the assignment but I am unable to do so via CURL.

I am able to create files at "/api/v1/courses/30928/files" with the token. So I can tell up to that point things are correct and the general approach I am using is working, but I am unable to submit files into assignments using the API URI "/api/v1/courses/:course_id/assignments/:assignment_id/submissions/self/files" (due to the above error) as suggested at: https://canvas.instructure.com/doc/api/file.file_uploads.html

Any suggestions/help to troubleshoot this issue is greatly appreciated.

10 Replies
Stef_retired
Community Team
Community Team

 @raodm ​, due to the specialized nature of your question I've shared it with the Canvas Developers​ group.

raodm
Community Participant

A follow-up question that I have -- Can an LTI tool upload files as part of a homework submission via the API URI /api/v1/courses/:course_id/assignments/:assignment_id/submissions/self/files ?

garth
Community Champion

It seems you might get this error if the file has not completed the upload yet.

I'm not sure how you are uploading the file, are you monitoring the upload progress?

It has been some time since I worked with file uploads, I'll try to reproduce when I have a few minutes.

Stef_retired
Community Team
Community Team

 @raodm ​, we haven't heard from you in a while. Please take a moment to let us know if you've been able to resolve this issue--and if you have not, please provide us with additional details so that we can continue to help.

garth
Community Champion

 @raodm ​ I apologize, I lost track of this question.

I recently posted sample code in .NET demonstrating the steps taken to upload a file:

Specifically look at the file clsFileUpload.cs, even if you are not using c# you should be able to follow the sequence of events.

I hope this helps.

raodm
Community Participant

Thank you for the example. I am pretty sure my file uploading process is correct because I am able to upload files to different locations other than to an assignment folder. The upload process is not in question here.

The question is really about file uploading but uploading to a specific URI from an LTI tool ("/api/v1/courses/:course_id/assignments/:assignment_id/submissions/self/files") associated with an assignment as suggested in Instructure's documentation at:https://canvas.instructure.com/doc/api/file.file_uploads.html

I currently think the answer is -- "An LTI tool cannot upload files to the assignments URI because the submission is via an external tool". I was hoping that some one would be able to confirm the above answer for me.

garth
Community Champion

 @raodm ​ sorry for my misunderstanding.

Currently I do not have an assignment type that accepts a file upload.

I will create one and let you know what results I get.

Question: how are your representing "self" in your API call?

Are you generating an Oauth2 token to make the API call on behalf of the user?

Or are you masquerading as the user?

Let me know, and I'll test using the same technique to more closely match your scenario.

raodm
Community Participant

 @garth ​ I am generating an Oauth2 token to make the API call on behalf of the user.

Robbie_Grant
Community Coach
Community Coach

 @raodm ,

Were you able to find an answer to your question? I am going to go ahead and mark this question as answered because there hasn't been any more activity in a while so I assume that you have the information that you need. If you still have a question about this or if you have information that you would like to share with the community, by all means, please do come back and leave a comment.  Also, if this question has been answered by one of the previous replies, please feel free to mark that answer as correct.

 

Robbie