2

I have passed an image obtained from Microsoft Graph API to pictureURL() function. But getting this error:

TypeError [ERR_INVALID_ARG_TYPE]: The "chunk" argument must be of type string or an instance of Buffer. Received an instance of ArrayBuffer
    at ClientRequest.end (_http_outgoing.js:768:13)
    at features.constructor.writeBody (K:\Project\project-backend\node_modules\aws-sdk\lib\http\node.js:137:14)
    at features.constructor.handleRequest (K:\Project\project-backend\node_modules\aws-sdk\lib\http\node.js:105:12)
    at executeSend (K:\Project\project-backend\node_modules\aws-sdk\lib\event_listeners.js:342:29)
    at Request.SEND (K:\Project\project-backend\node_modules\aws-sdk\lib\event_listeners.js:356:9)

I want to upload the image obtained from Graph API to s3 bucket.

Microsoft Graph API for getting the image of a user-

 https://graph.microsoft.com/v1.0/users/${id | userPrincipalName}/photo/$value

Function in which I am passing the obtained image is -

async pictureURL(image, userID) {
try {
  const uploadParams = { Bucket: config.s3bucket.name };
  const bufferData = await image.arrayBuffer();
  uploadParams.Body = bufferData;
  uploadParams.Key = 'example.jpg'// path.basename(image);
  s3.putObject(uploadParams, (err, data) => {
    if (err) {
      console.log('Error', err);
      return;
    }
    console.log('Upload Success', data.Location);
    return data.Location;
  });
} catch (error) {
  console.log(error)
}
}

image format returned by the graph-api -

image: 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 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 ... 4355 more bytes> 
  }
Shiva Keshav Varma
  • 3,398
  • 2
  • 9
  • 13
Madhvi Mittal
  • 67
  • 1
  • 8

0 Answers0