Hello, Running into some issues with updating a user's profile image through the POST...
Hello,
Running into some issues with updating a user's profile image through the POST /d2l/api/lp/(version)/profile/myProfile/image API. I’m using Node and the multer, form-data, and axios npm libraries.
*Update*
So far I have:
// from multer — upload.single(‘file)
const fileInfo = {
name: file.originalname,
contentType: file.mimetype,
buffer: file.buffer,
size: file.size,
};
const form = new FormData();
form.append('profileImage', fileInfo.buffer);
const config = {
method: 'post',
headers: {
...form.getHeaders(),
},
data: form,
};
await axios(config)
.then((response) => {
console.log(JSON.stringify(response.data));
})
.catch((error) => {
console.log(error);
});
I pulled this axios code from Postman. When this request is translated to HTTP, it is:
POST /api/lp/1.9/profile/myprofile/image?x_a={app_id}&x_b={user_id}&x_c={app_key}&x_d={user_key}&x_t={unix_timestamp_in_seconds}' HTTP/1.1
Host: some-edu.brightspace.com
Content-Length: 188
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW
----WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="profileImage"; filename="profile.png"
Content-Type: image/png
(data)
----WebKitFormBoundary7MA4YWxkTrZu0gW
It looks like the example provided on the File uploads page for updating a profile image (https://docs.valence.desire2learn.com/basic/fileupload.html#simple-uploads), besides the boundary created by Postman. The axios response shows a redirect to /d2l/error/404/.
Not quite sure what to try next. Any help would be appreciated.
Thanks,
Dominic
Answers
-
Hi @Dominic DeSantis ,
I think you are really close. At the beginning of your route, it is missing the `d2l ` segment. The full route should look like:
POST https://some-edu.brightspace.com/d2l/api/lp/1.30/profile/myprofile/image?x_a={app_id}&x_b={user_id}&x_c={app_key}&x_d={user_key}&x_t={unix_timestamp_in_seconds}'
-
Hi @Richard Martin ,
Thanks for looking into this. Seems like the the "/d2l" segment was lost somewhere while creating the authenticated URL. After adding it back I was able to successfully submit the request from Postman.
Thanks!