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:

And I'm trying to follow the instructions for a "simple" upload here:

But obviously I'm doing something wrong.

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

Content-Disposition: form-data;
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?


Best Answer

  • Ian.P.710
    Ian.P.710 Posts: 25
    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 '' \--header 'Authorization: Bearer AccessToken' \--form 'Image=@"/C:/Users/ipeach/OneDrive - D2L Corporation/Pictures/RobinResize.jpg"'

    Hope it helps.