Help with uploading photo image to course offering via API

Hi, I'm trying to upload an image (photo jpg) to a course offering. I'm using the API listed here: https://docs.valence.desire2learn.com/res/course.html#put--d2l-api-lp-(version)-courses-(orgUnitId)-image

And I'm trying to follow the instructions for a "simple" upload here: https://docs.valence.desire2learn.com/basic/fileupload.html#simple-uploads

But obviously I'm doing something wrong.

I'm sending this in the body (as a postfield):

CURLOPT_POSTFIELDS => array(
'--xxBOUNDARYxx
Content-Disposition: form-data;
name="Image";
filename="module-cover.jpg"
Content-Type: image/jpg' => '',
'file'=> new CURLFILE('/path_to/module-cover.jpg'),
'--xxBOUNDARYxx--' => '')

The upload supposedly "succeeds" with a 200 response.

When I go to Course > Course Admin > Course Offering Information, the name of the image shows up as the course image, but it shows zero bytes.

If I manually add this same image via the Brightspace UI (Course Offering Information page), it works and displays as expected.

Any advice?

Thanks!

Best Answer

  • Ian.P.710
    Ian.P.710 Posts: 26
    edited September 2023 Answer ✓

    Just tried it with Postman with the following to my test brightspace.
    PUT {{BrightspaceDomain}}/d2l/api/lp/{{lpversion}}/courses/{{orgunitid}}/image
    Body form-data key = Image Value = RobinResize.jpg (my image file)

    Below is the cURL generated by Postman to do the same command with my domain name removed and the accesstoken removed and replace with the word AccessToken.

    curl --location --request PUT 'https://xxxxxxxxxx.desire2learn.com/d2l/api/lp/1.44/courses/13733/image' \--header 'Authorization: Bearer AccessToken' \--form 'Image=@"/C:/Users/ipeach/OneDrive - D2L Corporation/Pictures/RobinResize.jpg"'

    Hope it helps.

Answers