Community

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
raodm
New Member

How to specify multiple 'file_ids' in API call?

Jump to solution

Hello,

I am able to successfully submit 1 file (via POST /api/v1/courses/:course_id/assignments/:assignment_id/submissions) for an Assignment (of type online_upload). It works as expected.

However, I am unable to submit 2 (or more) files for an Assignment. No matter what combination I try (that is, comma separated, blank separated, in square-brackets, without square-brackets, etc.)  Here is the request that I am currently trying:

curl 'https://test.instructure.com/api/v1/courses/27332/assignments/229429/submissions' \
    -F 'comment[text_comment]=This is assignment submission with 2 files in it' \
    -F 'submission[submission_type]=online_upload' \
    -F 'submission[file_ids][]=3088689, 3088688' \
   -H 'Authorization: Bearer  BigTokenString'

The submission is created but with just the first file. The second file (id 3088688) is not included in the submission as shown in the screenshot (part of Canvas web application) below:

189268_pastedImage_9.png

I will be thankful if some one could help me figure out what is the correct format to be used to submit multiple files as part of a submission.

1 Solution
raodm
New Member

I briefly reviewed the source code at canvas/submissions_controller.rb at master · icelab/canvas · GitHub

Looks like the code fragment on Line #283 (below) is considering file_ids as an array:

     if params[:submission][:file_ids].is_a?(Array)

        attachment_ids = params[:submission][:file_ids]

      else

        attachment_ids = (params[:submission][:attachment_ids] || "").split(",")

      end

Googling for passing arrays to Perl code indicated that for arrays, the field needs to be repeated in the input form. So repeating file_ids in my request (as shown below) fixed the issue form me.

curl 'https://test.instructure.com/api/v1/courses/27332/assignments/229429/submissions' \
    -F 'comment[text_comment]=This is assignment submission with 2 files in it' \
    -F 'submission[submission_type]=online_upload' \     -F 'submission[file_ids][]=3088689' \
    -F 'submission[file_ids][]=3088688' \
    -H 'Authorization: Bearer  BigTokenString'

View solution in original post

2 Replies
kona
Community Coach
Community Coach

 @raodm ​, I'm not sure of the answer to this question, but I'm going to share this with the Canvas Developers​ group in the Community to see if they can help. They are the back-end programmers who do this type of stuff.

raodm
New Member

I briefly reviewed the source code at canvas/submissions_controller.rb at master · icelab/canvas · GitHub

Looks like the code fragment on Line #283 (below) is considering file_ids as an array:

     if params[:submission][:file_ids].is_a?(Array)

        attachment_ids = params[:submission][:file_ids]

      else

        attachment_ids = (params[:submission][:attachment_ids] || "").split(",")

      end

Googling for passing arrays to Perl code indicated that for arrays, the field needs to be repeated in the input form. So repeating file_ids in my request (as shown below) fixed the issue form me.

curl 'https://test.instructure.com/api/v1/courses/27332/assignments/229429/submissions' \
    -F 'comment[text_comment]=This is assignment submission with 2 files in it' \
    -F 'submission[submission_type]=online_upload' \     -F 'submission[file_ids][]=3088689' \
    -F 'submission[file_ids][]=3088688' \
    -H 'Authorization: Bearer  BigTokenString'