Profile Image Upload Post Content

imholzj
imholzj Posts: 7 🔍

I've been following the profile image upload request format from this page in the docs:

https://docs.valence.desire2learn.com/basic/fileupload.html#simple-uploads

POST https://someLMShost.edu/d2l/api/lp/{version}/profile/myProfile/image HTTP/1.1
Content-Type: multipart/form-data; boundary=xxBOUNDARYxx
Content-Length: {POST body length in bytes}

--xxBOUNDARYxx
Content-Disposition: form-data; name="profileImage"; filename="my_new_profile_image.png"
Content-Type: image/png

{image file data bytes}
--xxBOUNDARYxx--

Although I'm posting for other users (e.g. /d2l/api/lp/1.42/profile/user/29243/image)

The post is successful, but I'm guessing I didn't format the image data correctly.

Is there more detail of the the contents of the request.

here's the head of what I posted:

POST / HTTP/1.1
Authorization: Bearer eyJhbGciOiJSUzI1NiIsImtpZCI6IjI4YzQ2ZGYzLTMxZmUtNDMzOS1hMGU1LTQzZWJjYTQ3MjkyOSIsInR5cCI6IkpXVCJ9.eyJuYmYiOjE2ODQ2MzI5OTcsImV4cCI6MTY4NDYzNjU5NywiaXNzIjoiaHR0cHM6Ly9hcGkuYnJpZ2h0c3BhY2UuY29tL2F1dGgiLCJhdWQiOiJodHRwczovL2FwaS5icmlnaHRzcGFjZS5jb20vYXV0aC90b2tlbiIsInN1YiI6IjQ1ODc2IiwidGVuYW50aWQiOiI0ZmM5MDg3NS05ZWYyLTQzNzItOWI0ZS01NTQ3NDQwMTgwOWMiLCJhenAiOiI1MjY1OTRmYy0wNzIzLTRlMWItYTBhMS02MTg1YjE4MTU1N2EiLCJzY29wZSI6InByb2ZpbGU6KjoqIHVzZXJzOio6KiIsImp0aSI6ImI0YjkyODBiLTU3OTktNGJjNS05MDYwLTBkNDM3ODdiNjM2MyJ9.X7nROVi28giDFqNj_hkcklZ2p3CAM2BRgDsxQdzS6Aw7jBUuapM2Jou2uLETj5kJyCCLp0CCupsR5cswJRGJV9XpnmdyApUw2xQ9JPbZ5PNcItD0anl9sKp5rVGiKJAnQv1Ll7s9C9fB_UtJwonTObsWxIY3goJNiVTuCIcCx_ayrQ0DKM2E7duKyUbnpLkKaB4LS1UHYZGoA063hDgn8wFClOfDLbhGjE_wKnzFqd3YYlsGsmduX0E0SM2DdIrqZS_V_jRJ-5LASKR9RXxAAq0_ejuPD5rphJBKW4i8uFZoH3z9fzbCiiH3NrObriUXWTKiM5audA6dVHbuuofe
Content-Type: multipart/form-data; boundary=xxBOUNDARYxx
User-Agent: Java/1.8.0_202
Host: localhost:8888
Accept: text/html, image/gif, image/jpeg, *; q=.2, /; q=.2
Connection: keep-alive
Content-Length: 1239702

--xxBOUNDARYxx
Content-Disposition: form-data; name="profileImage";filename="my_new_profile_image.png"
Content-Type: image/jpeg

data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEASABIAAD/4gIoSUNDX1BST0ZJTEUAAQEAAAIYYXBwbAQAAABtbnRyUkdCIFhZWiAH5gABAAEAAAAAAABh
Y3NwQVBQTAAAAABBUFBMAAAAAAAAAAAAAAAAAAAAAAAA9tYAAQAAAADTLWFwcGzs/aOOOIVHw220vU962hgvAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAApkZXNjAAAA/AAAADBjcHJ0AAABLAAAAFB3dHB0AAABfAAAABRyWFlaAAABkAAAABRnWFlaAAAB
pAAAABRiWFlaAAABuAAAABRyVFJDAAABzAAAACBjaGFkAAAB7AAAACxiVFJDAAABzAAAACBnVFJDAAABzAAAACBtbHVjAAAAAAAA
AAEAAAAMZW5VUwAAABQAAAAcAEQAaQBzAHAAbABhAHkAIABQADNtbHVjAAAAAAAAAAEAAAAMZW5VUwAAADQAAAAcAEMAbwBwAHkA
cgBpAGcAaAB0ACAAQQBwAHAAbABlACAASQBuAGMALgAsACAAMgAwADIAMlhZWiAAAAAAAAD21QABAAAAANMsWFlaIAAAAAAAAIPf
AAA9v////7tYWVogAAAAAAAASr8AALE3AAAKuVhZWiAAAAAAAAAoOAAAEQsAAMi5cGFyYQAAAAAAAwAAAAJmZgAA8qcAAA1ZAAAT
0AAACltzZjMyAAAAAAABDEIAAAXe///zJgAAB5MAAP2Q///7ov///aMAAAPcAADAbv/hBT5odHRwOi8vbnMuYWRvYmUuY29tL3hh
cC8xLjAvADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1s
bnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IlhNUCBDb3JlIDUuNS4wIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8v

Tagged:

Answers

  • Exactly how you will do this probably is mostly affected by the language you're using for your API-using application, and the library you're using to do HTTP requests. The format of the API request for profile images uses the "simple file upload" pattern as described in RFC1867 and related standards. For example, in Python (using the requests library), it's pretty straightforward: you read the image file bytes in the standard way and then follow the pattern in requests for passing up the file bytes in a multipart-encoded POST call. The actual profile image data should be the raw bytes of the file, which Brightspace can separate out as a MIME part via using your boundary marker in the request, and the extra line between the MIME-part header (the Content-Disposition and Content-Type part headers in your example) and the file's data bytes.

  • imholzj
    imholzj Posts: 7 🔍

    I think you're saying the above POST looks OK, except for the image data not being the bytes from the file. I've made that edit and the POST still seems to be successful, but the image shows as broken in my profile (and generates a 500 error when I try to request it via API.)

    Here is what the head of the post looks like now:

    POST / HTTP/1.1
    Authorization: Bearer eyJhbGciOiJSUzI1NiIsImtpZCI6IjJ . . .
    Content-Type: multipart/form-data; boundary=xxBOUNDARYxx
    User-Agent: Java/1.8.0_202
    Host: localhost:8888
    Accept: text/html, image/gif, image/jpeg, *; q=.2, /; q=.2
    Connection: keep-alive
    Content-Length: 1682403

    --xxBOUNDARYxx
    Content-Disposition: form-data; name="profileImage";filename="my_new_profile_image.jpeg"
    Content-Type: image/jpeg

    ����JFIFHH��(ICC_PROFILEapplmntrRGB XYZ �acspAPPLAPPL���-appl����8�G�m��Oz�/