File upload using new Course Files APIs

Matthew.T.222
Matthew.T.222 Posts: 12 🌱
edited July 27 in Development

Hi,

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.

Thanks,

Matthew

Tagged:

Best Answer

  • Furkan.K.312
    Furkan.K.312 Posts: 55
    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

Answers

  • 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: 12 🌱

    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: 12 🌱

    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}.desire2learn.com/d2l/upload/{key} or similar.