title: Error 3 uploading video to Google Photos with Powershell (Works for pictures)
body: <p>I am using the following code to upload photos and videos to Google Photos using Powershell. The code works perfectly for pictures, but will fail when uploading a video (which is accepted in Google Photos when this is uploaded through a browser).</p>
  <p>When attempting to upload a video, raw bytes upload will succeed, but <code>mediaItems.batchCreate</code> will fail with status.code <code>3</code> and status.message <code>&quot;Failed: There was an error while trying to create this media item.&quot;</code>
  Could this be due to a wrong mime type in the header?</p>
  <pre><code>Function GP-UploadMedia (){
      &lt;# 
      .SYNOPSIS
        Uploads a Google Photos media (picture/video)
      
      .Description  
        Parameters: 
          - album id
          - media path
        Returns:
          - picture id
  
      #&gt;
      [CmdletBinding()]
          param (
              [Parameter(Mandatory=$true)]
              [string]$album_id,
              [Parameter(Mandatory=$true)]
              [string]$media_path
  
          )
  
      # refresh tokens if required
      G-RefreshTokens
      
      # 1st step: upload raw bytes
      $requestUri = &quot;https://photoslibrary.googleapis.com/v1/uploads&quot;
      $mime_type = [System.Web.MimeMapping]::GetMimeMapping($media_path);
      $Headers = @{
          Authorization = &quot;Bearer $($Global:Tokens.access_token)&quot;;
          ContentType = &quot;application/octet-stream&quot;;
          &quot;X-Goog-Upload-Content-Type&quot; = $mime_type;
          &quot;X-Goog-Upload-Protocol&quot; = &quot;raw&quot;;
          }
  
      $body = $media_path;
  
      try {
          $upload_token = Invoke-RestMethod -Headers $Headers -InFile $body -Uri $requestUri -Method POST
      }
      catch {
          # Something went wrong. Investigate!
          dieOnError ([System.IO.StreamReader]::new($_.Exception.Response.GetResponseStream()));
      }
   
      # refresh tokens if required
      G-RefreshTokens
  
      # 2nd step: pair raw bytes to Google Photo media (picture/video)
      $requestUri = &quot;https://photoslibrary.googleapis.com/v1/mediaItems:batchCreate&quot;
      $Headers = @{
          Authorization = &quot;Bearer $($Global:Tokens.access_token)&quot;;
          }
    
      $body = [PSCustomObject]@{ 
          albumId = $album_id;
          newMediaItems = @( 
              [PSCustomObject]@{
                  description = &quot;&quot;;
                  simpleMediaItem = [PSCustomObject]@{ 
                      fileName = (Split-Path $media_path -leaf);
                      uploadToken = $upload_token;
                      }
              }
          )
      } 
      $myJson = $body|ConvertTo-Json -Depth 4
  
      try {
          $Response = Invoke-RestMethod -Headers $Headers -Body ($myJson)  -Uri $requestUri -Method POST -ContentType &quot;application/json; charset=utf-8&quot;;
      }
      catch {
           # Something went wrong. Investigate!
           dieOnError ([System.IO.StreamReader]::new($_.Exception.Response.GetResponseStream()));
      } 
  
      return  $Response.newMediaItemResults.MediaItem.id;
  }
  </code></pre>