D2L Valence - Uploading file to a group locker

146 views Asked by At

My goal is to create a group locker for every person in the class and upload a file to that locker. So first I'm calling

  POST /d2l/api/lp/(version)/(orgUnitId)/groupcategories/

in order to create a category. That also creates a group for every user and automatically enrolls them. I then create a locker for each group in the category by calling

POST /d2l/api/lp/(version)/(orgUnitId)/groupcategories/(groupCategoryId)/locker

That works perfectly and at this point every student has it's own group with a locker assigned to the group. It is then up to the file uploading part. Using the

POST /d2l/api/le/(version)/(orgUnitId)/locker/group/(groupId)/(path)

call I am trying to send a file, but all I get is a 404 error with no response provided. According to D2L's website, 404 would indicate that the group doesn't exists, which is not true since the groupId is received from the first call and works for the second one. For the header I use the array:

$h = array(
        'Content-Type: multipart/form-data', 
);

The contents are:

$contents = array("FileDescription" => json_encode(
     array("Description" => "YY", 
           "IsPublic" => true
      )),
       "FILEFILE");

The POST is performed using cURL (php) and the code is mostly the code provided on D2L's website (a modified version of doValenceRequest function). I've tried multiple different headers, as well as different formats for the contents array. No matter what I do, the 404 error is being returned. I've even tried to just create a simple folder instead of uploading a file, but got the same issue. Am I doing something wrong?

1

There are 1 answers

0
Viktor Haag On BEST ANSWER

Locker file uploads use the simple upload (not resumable) pattern, but, because you send a JSON document along with the file data, you have to use the RFC2388 multipart/mixed pattern, with a POST. See simple upload section on multi-part mixed patterns to see what those HTTP packets looks like.

Of particular note: the HTTP content-type is multipart/mixed and not multipart/form. Also, please be certain that you're actually sending a POST, not a PUT. Some HTTP libraries are pretty finicky around the use of multipart\mixed payloads, and you may find yourself having to hand-cook the entire HTTP request body to get the parts correctly formatted, and tune the headers a bit, before you send the request.

Note also that you should always be sending the JSON document part first in the list of parts, just as in the pattern examples in the documentation.