I am able to retrieve a blob object of my profile picture from the microsoft graph api. However, I don't know how to save the blob to a file like I would with python.
When I console.log the blob itself it comes up like this:
console.log(profilepic)
Blob {
[Symbol(type)]: 'image/jpeg',
[Symbol(buffer)]: <Buffer ff d8 ff e0 00 10 4a 46 49 46 00 01 01 01 00 60 00 60 00 00 ff db 00 43 00 08 06 06 07 06 05 08 07 07 07 09 09 08 0a 0c 14 0d 0c 0b 0b 0c 19 12 13 0f ... 9870 more bytes>
so I thought I could try to save it to file like so:
console.log(profilepic)
test = await profilepic.arrayBuffer();
var imageName = 'test.jpg';
fs.createWriteStream(imageName).write(test);
but got an error like this:
(node:24176) UnhandledPromiseRejectionWarning: TypeError [ERR_INVALID_ARG_TYPE]: The "chunk" argument must be one of type string or Buffer. Received type object
This is my first time trying something like this in nodeJS.
In python I would be able to do the same thing like this:
the graph_user_picture.content
is the same as the profilepic
blob.
graph_user_picture = requests.get(app_config.USERPHOTO,
headers={"Authorization": "Bearer " + token['access_token']})
file = open("static/user_iamge"+session["user"]["name"]+".png", "wb")
file.write(graph_user_picture.content)
file.close()
How can I save a blob image to a folder?