File upload using new Course Files APIs

Matthew.T.222 Posts: 19 🌱
edited July 2023 in Development


I saw the release of the new Course Files APIs that allow users to upload files to a course offering and am excited to try them out!

In particular, I am attempting to upload a file to a course, first with the /upload API followed by the /save API. I have successfully received the expected 308 response from /upload, but am struggling to figure out the correct parameters for /save.

The documentation for the route says I need two form parameters: fileKey and relativePath. For fileKey, is it expecting the full Location string (/d2l/upload/{key}) , or just the {key}portion? Also, how is the file itself attached?

Reading the additional documentation on resumable file uploads, I also experimented with adding the Content-Type and Content-Range headers, but have thus far received 400: Invalid Parameters responses.

Thus far, I've been testing these calls in Postman, so I'm not sure if any of these parameters/headers that are auto-generated by Postman are incorrect. I also tried the suggestion to make a request with Content-Range: bytes */8813 to get the current status (presumably 0), but have not gotten the expected 308 response.

Any advice on how to proceed/troubleshoot would be greatly appreciated! I have attached a few screenshots from Postman with the headers and form body I am using.




Best Answer

  • Furkan.K.312
    Furkan.K.312 Posts: 58
    Answer ✓

    Hi Matthew,

    I am not sure.
    For testing, we uploaded the file manually for testing puposes

    • You can see here a format that works for me. Topic1 is a folder in the course manage file area

    Thank you


  • Furkan.K.312

    Hi Matthew,
    Thank you for connecting with the community.

    Did you try the “file key” parameter expected is just the {key}?

    Thank you

  • Matthew.T.222
    Matthew.T.222 Posts: 19 🌱

    Hi Furkan,

    I've tried a few different combinations. Here's a list of form values and headers I've experimented with—none have been met with success thus far:

    • Form values:
      • For the file, trying a key of "file" and blank (no key)
      • For the "fileKey"
        • using the full value that is provided in the Location header when calling /upload (400 error)
        • using just the key (500 error).
    • Headers:
      • Content-Type: Postman will auto-populate this with multipart/form-data; … when uploading a file. I have also tried overwriting this with the explicit content type of the file (e.g. text/text or text/html).
      • Content-Range:
        • Omitted as the upload file data documentation says this can if uploading the entire file at once.
        • Using the batch range (e.g. bytes 0-11/11)
        • Trying to poll the current status (i.e. bytes */11)

    Here are two screenshots showing the configuration with /d2l/upload/{{key}} and just {{key}} as you suggested. Just {{key}} produces a 500 error.

  • Matthew.T.222
    Matthew.T.222 Posts: 19 🌱

    Thank you, Furkan!

    I was not understanding that the Location value provided by the /upload method was an API endpoint for where to upload the file and that /save is the "attach" action to make a relationship between the file key and the where it should live.

    I would suggest some edits to the documentation to make this a little clearer. Knowing how it works now, I see it does explain these steps fully, but I feel like it relies on some inference from the reader. I think it's also confusing that the diagram lists the endpoint as https://d2l/upload/{key} which omits the domain and org subdomain and should be changed to https://{org_name}{key} or similar.

  • vdizzle...423

    is it possible to do this with the api test tool and not post man? If so, can someone provide an example of what needs get populated in the tool

  • Corné.O.116
    Corné.O.116 Posts: 1 🌱
    edited March 22


    Would it be possible to share the postman collection on github or update the existing one?

    I'm trying to get the resumable upload to start but keep getting:

    416 Requested Range Not Satisfiable

    URL: https://[domain]/d2l/api/lp/1.46/[orgUnitId]/managefiles/file/upload

    Is the body of the post supposed t be empty?


    import requests

    url = "https://[domain]/d2l/api/lp/1.46/[orgUnitId]/managefiles/file/upload"
    payload = {}

    headers = { 

    'X-Upload-Content-Type': 'image/png', 

    'X-Upload-Content-Length': '239988', 

    'X-Upload-File-Name': 'test.png', 

    'Authorization': 'Bearer [token details]'


    response = requests.request("POST", url, headers=headers, data=payload)