How to interpret data returned when making banner image API call?

Options
Gavin.McGruddy
Gavin.McGruddy Posts: 2 🌱
edited November 2022 in Development

Hi there,

 

My team is currently creating a custom student dashboard widget for the main homepage.

 

Pulling the various course information is working, but when trying to make the banner image call, we've hit a snag.

 

This is the API call:

 

GET /d2l/api/lp/(version)/courses/(orgUnitId)/image

 

And although there isn't any network/server errors, this is the data returned:

 

 

image-error

The documentation brings out that "a file stream containing the current course offering’s image" is returned, but my question is how can I interpret this into an HTML image tag to insert into the the rest of the HTML content we're coding?

 

Thanks in advance!

 

Gavin McGruddy

Tagged:

Answers

  • Justin.Carvalho341
    edited November 2022
    Options

    Hey Gavin,

     

    If you're making the dashboard widget within Brightspace, you'll be able to put the route straight in your image tag like so:

     

    <img src="http://(brightspaceUrl)/d2l/api/lp/(version)/courses/(orgUnitId)/image"></img>

     

    Outside brightspace, you'll be able to build an authenticated route and use the same method.

     

    If you really want to work with the byte array, you could also convert it to a base64 string, and set up your image tag like so:

     

    <img src="data:image/png;base64,(Base64String)">

     

    But I'd using the url method instead.

     

  • Gavin.McGruddy
    Gavin.McGruddy Posts: 2 🌱
    edited November 2022
    Options

    Hi Justin,

     

    Yes I'm making the dashboard widget within Brightspace, and so that first option worked like a charm!

     

    Thanks for your help!

     

    Gavin