File upload using new Course Files APIs
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
Best 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
-
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).
- using the full value that is provided in the
- 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
ortext/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
)
- Content-Type: Postman will auto-populate this with
Here are two screenshots showing the configuration with
/d2l/upload/{{key}}
and just{{key}}
as you suggested. Just{{key}}
produces a 500 error. - Form values:
-
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 tohttps://{org_name}.desire2learn.com/d2l/upload/{key}
or similar. -
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
-
Hi,
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)
print(response.status_code)
print(response.text)
``` -
Postman issue solved here:
https://community.d2l.com/brightspace/discussion/4610/416-error-when-initiating-upload