title: Can't Upload Image with Google Photos API using NodeJS
body: <p>I have application built in NodeJS it is suppose to upload pictures to google photos using google photos API
  for the authentication part I'm doing successfully, i have problem when i try to upload pictures i receive the upload token without problem but when i try to use mediaItems:batchCreate it returns :</p>
  
  <pre><code>"status": {
      "code": 3,
      "message": "Failed: There was an error while trying to create this media item."
    }
  </code></pre>
  
  <p>Here is my code to convert the image into base64 :</p>
  
  <pre><code>var base64str = fs.readFileSync('1.jpg', 'base64');
  </code></pre>
  
  <p>And here is the request where i get response the upload token :</p>
  
  <pre><code>request({
  method: 'post',
  headers: {
  'content-type' : 'application/octet-stream',
  'Authorization': `Bearer ${userToken}`,
  'X-Goog-Upload-File-Name' :  '1.jpg',
  'X-Goog-Upload-Protocol' : 'raw'
  },
  url: `https://photoslibrary.googleapis.com/v1/uploads`,
  rejectUnauthorized: false,
  body: base64str
  }, function(err,response,body) {
        console.log(body);
        });
  </code></pre>
  
  <p>Up to here i don't have issue because (body) response is the upload token and i receive it.
  now when i want to go to step#2 to request the mediaItems:batchCreate  here is the code :</p>
  
  <pre><code>let reqObject = {
      newMediaItems: [
        {
          description: "Test Image Uploading",
          simpleMediaItem: {
          uploadToken: body //Body is the upload token received from prev request
          }
        }
      ]
    };
  let reqObjectString = JSON.stringify(reqObject);
  
    request({
      method: 'post',
      headers: {
      'content-type' : 'application/json',
      'Authorization': `Bearer ${userToken}`,
      },
      url: `https://photoslibrary.googleapis.com/v1/mediaItems:batchCreate`,
      rejectUnauthorized: false,
      body: reqObjectString
    }, function(err,response,result) {
        console.log(result);
  });
  </code></pre>
  
  <p>The Expected Result here it's suppose to be the successful uploading media but instead i always get this respons :</p>
  
  <pre><code>{
    "newMediaItemResults": [
      {
        "uploadToken": "CAISmQMASsyg4MwSgB2y46/QI2yAAfw/uSeHZaiwGaskaT9J3SEvOtBg4bkOb9Fd0WMhE5OML8aMJMGZWNyC3Di/woTjLGD/VJMtKBk7bg1ZyK5CA+92vk0mjUWVR2LQhhTkEs02aHRr6EkCER3rxk3AqkhC+bxTIViLerUeoKigdlqozrEJXyCLM5U+Eqjdidi0e0hEFeLqs8Yz0V8YpyWQnN+zZUp/+R4pVT9fPXUOyNlsTj5OcMLrtC3Z/W9YnKhQA0O8io8LtmMBJTf04v3YPEtoNvJTd+k5Ux7qWQYJCS60V1R+hPl76jlryos3gnVaaCxHGH/TIMmtwo2zDH+vXTyktMhr82hdMON3Mm2PCfSbJawCLuHSNND9vojO11FEs7LVXAfY1UDDzVXwv4VV8tG9F3tQVI8/4YlkR+KJUjaX6/E4ZFWx67E+swqh16HN1RXXU211eCl36mPxsX35IGPEwvhpZ89LKfk+NU1fVuHB+pNLMNQ+mZOkKs0v6VLcN+nyMpOwjAstg4QUSJdCP+virY1a2uGKwYJh",      
          "status": {
          "code": 3,
          "message": "Failed: There was an error while trying to create this media item."
        }
  </code></pre>
  
  <p>Can anyone help, thanks in advance</p>