“块”参数必须是字符串类型或Buffer的实例。收到ArrayBuffer的实例

时间:2020-07-06 13:59:15

标签: node.js amazon-s3 microsoft-graph-api aws-sdk microsoft-graph-mail

我已将从Microsoft Graph API获得的图像传递给 pictureURL()函数。 但是出现此错误:

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)

我要将从Graph API获得的图像上传到s3存储桶。

用于获取用户图像的Microsoft Graph API-

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

我传递获得的图像的功能是-

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)
}
}
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> 
  }

0 个答案:

没有答案