How do we add attachments to Dropbox / Assignment Folders over the API?

Answers
-
Hey Mike,
In order to submit to an Assignment there are two API routes available, one is specific for group Assignments and the other is for an Individual.
The Group Assignment route:
The Individual Assignment route:
Both of the routes are POST and take a body that is of type multipart/mixed. This page has examples of what the body should look like for various file uploads. The Assignment route should be highlighted approximately half way down the page under the Upload to Dropbox heading:
Hope that helps,
Dave
-
That might not be exactly what you are looking for. If you are looking for an API to add attachments as part of the Assignment folder it looks like that is not available at this time. I recommend posting your idea for this API over in the Product Idea Exchange(PIE). You can find an overview of the PIE if you are not familiar with it here:
https://community.brightspace.com/s/article/ka3610000000et4AAA/Product-Idea-Exchange-Overview
Hope that helps,
Dave
-
Thanks for the confirmation @_David _Wagler. I'll go down my Plan B path of using NightmareJS in my node migration app to get this working. Nightmare was super helpful getting Samigo Exams out of Sakai. Killer tool.
-
-
@_David _Wagler Here's where I am with hacking an upload to the Dropbox/Assignment folder http://screencast-o-matic.com/watch/cbjr3YlND1
I'm running this with the Electron browser visible for debugging. Do you know of any other ways to upload a file and attach it to the Assignment?
-
Maybe I WebDAV the file into the course's enforced content, then use the Course Offering Files option in the Add a File dialog instead of the My Computer option. Hmmmm
-
Hey @Deleted Account ,
Based on your video, it looks like you have the Locker tool enabled. With the current user that you are performing the login with you could upload files to their locker using APIs. Here is the documentation for the Locker APIs:
Uploading to the locker would allow you to choose a file within locker, within the dialog, instead of having to use the My Computer option.
I hope that helps,
Dave
-
@_David _Wagler
Do you have a code snippet showing how to structure the "multipart post body containing file data"?
Preferably in JS, but I'll take whatever ya got. I'm trying to understand how to set the file meta and provide the file data in one go.
Thanks,
Mike
-
I've coded my solution, but it's air guitar at this point.
In uploading to the logged in user's locker, I captured the attached request. I receive the following Response.
{"type":"http://docs.valence.desire2learn.com/res/apiprop.html#invalid-parameters","title":"Invalid Parameters","status":400,"detail":"Request has missing or invalid parameters."}
I think my construct of the multipart/mixed request is correct and the file part looks right. I'm guessing it's something wrong with my FileDescription (JSON composite) block.
@_David _Wagler or @Joshua Vienneau Can you let me know what part of my Request is incorrect?
-
Hey @Deleted Account ,
I don't have a code sample I know of off-hand, but I'll take a look for you. The best I can give you is what the body would look like for the request to upload a file to locker. Here is a link to examples of a multipart post body:
http://docs.valence.desire2learn.com/basic/fileupload.html
The best example for your use case is to look at the "Upload to course content." example.
In this case the JSON you would send would change to look like the JSON described in the Locker API.
{
"Description": <string>,
"IsPublic": <boolean>
}
Overall I think your body for the request would look like:
--xxBOUNDARYxx
Content-Type: application/json
{"Description": "Test Description", "IsPublic": false}
--xxBOUNDARYxx
Content-Disposition: form-data; name=""; filename="file.txt"
Content-Type: text/plain
This is a sample text file
with some text content.
--xxBOUNDARYxx--
In addition to this you need the headers that are listed in the examples:
Content-Type: multipart/mixed;boundary=xxBOUNDARYxx
Content-Length: {POST body in length in bytes}
I hope this helps,
Dave
-
Hey @Deleted Account ,
I don't believe you need the "FileDescription" part of the JSON in your provided example. I think it should just be:
{ "Description": "description", "IsPublic": false }
for the JSON portion of the body.
I hope that helps,
Dave
-
Hi @_David _Wagler
I really appreciate the support on this hackalicious solution.
Attached is the updated Request. I receive a simple 400 Response with a body = Bad Request.
-
Oops. Forgot to attach the Request.
-
I also tried the call with the API Test Tool.
-
Hey @Deleted Account ,
I think the error is a result of the "path" parameter in the route which you currently have set to the name of your file. This I think can be blank if you want to simply upload it to the root folder of your locker so the URL would be:
/d2l/api/le/(version)/locker/myLocker/
If you wanted to add it to a folder you would add the folder with a trailing slash to the path, like:
/d2l/api/le/(version)/locker/myLocker/MyTestFolder/
* Note: In order to add it to the folder, the folder must already exist. You can create folders using this same API as described in the docs:
Thanks for trying it in the API tool, after looking at the tool it appears that it doesn't support the multipart/mixed content type with a file and a JSON. I'm going to bring this up with the team here and see if we can address that issue at some point.
Hope that helps,
Dave
-
Hey. Yeah @Joshua Vienneau corrected me on this one over Slack. We're iterating pretty quickly there.
So I don't kill the Community or future readers, I'll post the problem solution.
I do still need to post to PIE about adding an attachment to Assignment Folders....
-
Our final solution for this:
- POST an Assignment/Dropbox through an API returning with the Assignment ID
- GET the course offering code to match the OUID
- Upload the Assignment Folder's attachment to the knowable WebDAV URL path
- (messy part) Use NightmareJS to automate the web UI clicks necessary to import the attachment from the Course Offering Files (Heads Up: iframes)
Hopefully this post is useful to others in the near-term but unnecessary in the long.
Cheers,
Mike C.
-
Thanks for posting your solution @Deleted Account!
Categories
- All Categories
- 6 Thought Leadership
- 7 Known and Fixed Issues
- 6 Product Roadmap
- 553 Archived
- 10 Accessibility
- 28 Community Corner
- 2 Welcome
- Updates
- Member Spotlights
- 4 Events
- 242 Development
- 746 Customer Enablement
- Evaluate - Assess Student Learning
- Get Comfortable with Brightspace
- Communicate - Engage with Your Students
- 1 Create - Set up your Brightspace course
- Action - Add or create student activities
- 26 Partners
- 8 Product News
- 2022
- 2022 Release Notes
- 2021 Release Notes
- 4 Training
- andycat