title: Google Photos API mediaItems:batchCreate : NOT_IMAGE: There was an error while trying to create this media item
body: <p>I'm trying to upload an image file to Photos library using C#.</p>
  
  <p>Scopes used:
  <a href="https://www.googleapis.com/auth/photoslibrary" rel="nofollow noreferrer">https://www.googleapis.com/auth/photoslibrary</a> <a href="https://www.googleapis.com/auth/photoslibrary.appendonly" rel="nofollow noreferrer">https://www.googleapis.com/auth/photoslibrary.appendonly</a></p>
  
  <p>I'm generating uploadToken using below:</p>
  
  <pre><code>FileStream fS = new FileStream(fullPath, FileMode.Open, FileAccess.Read);
                  byte[] b = new byte[fS.Length];
                  fS.Read(b, 0, (int)fS.Length);
                  fS.Close();
                  var httpWebRequest = (HttpWebRequest)WebRequest.Create("https://photoslibrary.googleapis.com/v1/uploads");
                  httpWebRequest.ContentType = "application/octet-stream";
  
                  httpWebRequest.Headers.Add("Authorization:" + "Bearer " + auth_Token);
                  httpWebRequest.Headers.Add("X-Goog-Upload-File-Name:" + imageName);
                  httpWebRequest.Headers.Add("X-Goog-Upload-Protocol:" + "raw");
                  httpWebRequest.Method = "POST";
                  using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
                  {
                      streamWriter.Write(b);
                      streamWriter.Flush();
                      streamWriter.Close();
                  }
                  var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
  </code></pre>
  
  <p>Here i'm getting uploadToken successfully. After this i proceeded to create mediaItem like below:</p>
  
  <pre><code> httpWebRequest = (HttpWebRequest)WebRequest.Create("https://photoslibrary.googleapis.com/v1/mediaItems:batchCreate");
                      httpWebRequest.ContentType = "application/json";
                      httpWebRequest.Headers.Add("Authorization:" + "Bearer " + auth_Token);
                      httpWebRequest.Method = "POST";
                      using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
                      {
                          string albumID = "someid";
                          string itemDesc = "somedesc";
                          string jsonString = "{\"albumId\": \"" + albumID + "\",\"newMediaItems\": [{ \"description\": \"" + itemDesc + "\", \"simpleMediaItem\": { \"uploadToken\": \"" + uploadToken + "\" }}]}";
  
                          streamWriter.Write(jsonString);
                          streamWriter.Flush();
                          streamWriter.Close();
                      }
                      httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
  </code></pre>
  
  <p>Now as a response i'm getting:</p>
  
  <blockquote>
    <p>status": {
            "code": 3,
            "message": "NOT_IMAGE: There was an error while trying to create this media item."
          }</p>
  </blockquote>
  
  <p>I have googled much but couldn't found any solution for this issue OR any code block for mediaUpload using Google Photos Library API with example.</p>
  
  <p>Please suggest me where i'm doing wrong.</p>
  
  <p>-Reading/writing file bytes in a wrong way?</p>
  
  <p>-Using Json strings and writing in a wrong way?</p>
  
  <p>Please help me. Thank you.</p>