title: Getting error while uploading files to google drive in Delphi
body: <p>I am trying to upload files to Google drive using RestAPI in Delphi. But unable to upload files into Drive.
  Authentication to google drive succeeded but getting error while uploading files.
  Below is the error message I am getting.</p>
  
  <p><a href="https://i.stack.imgur.com/pbIcI.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pbIcI.png" alt="enter image description here"></a></p>
  
  <p>Here is my code:</p>
  
  <pre><code>var
    LURL: string;
    wv: Tfrm_OAuthWebForm;
    LToken: string;
     parents: TJSONArray;
    Folder: TJSONObject;
    upload_stream:TFileStream;
   local_filename : string;
   ttt: TJSONObject;
  begin
    edt_GoogleTasks_AuthCode.Text := '';
    edt_GoogleTasks_AccessToken.Text := '';
    edt_GoogleTasks_RefreshToken.Text := '';
  
    /// step #1: get the auth-code
    LURL := 'https://accounts.google.com/o/oauth2/auth';
    LURL := LURL + '?response_type=' + URIEncode('code');
    LURL := LURL + '&amp;client_id=' + URIEncode(edt_GoogleTasks_ClientID.Text);
    LURL := LURL + '&amp;redirect_uri=' + URIEncode('urn:ietf:wg:oauth:2.0:oob');
    LURL := LURL + '&amp;scope=' + URIEncode('https://www.googleapis.com/auth/tasks');
    // optional
    // LURL := LURL + '&amp;login_hint=' + URIEncode('user@example.com');
  
    wv := Tfrm_OAuthWebForm.Create(self);
    try
      wv.OnTitleChanged := self.OAuth2_GoogleTasks_BrowserTitleChanged;
      wv.ShowModalWithURL(LURL);
    finally
      wv.Release;
    end;
  
    /// step #2: get the access-token
  
    ResetRESTComponentsToDefaults;
  
    RESTClient.BaseURL := 'https://accounts.google.com/';
  
    RESTRequest.Method := TRESTRequestMethod.rmPOST;
    RESTRequest.Resource := 'o/oauth2/token';
    RESTRequest.Params.AddItem('code', edt_GoogleTasks_AuthCode.Text, TRESTRequestParameterKind.pkGETorPOST);
    RESTRequest.Params.AddItem('client_id', edt_GoogleTasks_ClientID.Text, TRESTRequestParameterKind.pkGETorPOST);
    RESTRequest.Params.AddItem('client_secret', edt_GoogleTasks_ClientSecret.Text, TRESTRequestParameterKind.pkGETorPOST);
    RESTRequest.Params.AddItem('redirect_uri', 'urn:ietf:wg:oauth:2.0:oob', TRESTRequestParameterKind.pkGETorPOST);
    RESTRequest.Params.AddItem('grant_type', 'authorization_code', TRESTRequestParameterKind.pkGETorPOST);
  
    RESTRequest.Execute;
  
    if RESTRequest.Response.GetSimpleValue('access_token', LToken) then
      // edt_GoogleTasks_AccessToken.Text := LToken;
      OAuth2_GoogleTasks.AccessToken := LToken;
    if RESTRequest.Response.GetSimpleValue('refresh_token', LToken) then
      // edt_GoogleTasks_RefreshToken.Text := LToken;
      OAuth2_GoogleTasks.RefreshToken := LToken;
  
      {$IF DEFINED(MsWindows)}
    local_filename :=  ExtractFilePath(ParamStr(0)) +'Sanjeev.txt';
  {$ENDIF}
   RESTResponseDataSetAdapter.AutoUpdate := false;
   RESTRequest.Params.Clear;
                                 RESTRequest.ClearBody;
   //RESTRequest.Method:=rmpost;
  //try
   RESTClient.BaseURL :=     'https://www.googleapis.com/upload/drive/v2/files?';
  
  
  
        upload_stream := TFileStream.Create(local_filename,fmOpenReadWrite);
    upload_stream.Position := 0;
  RESTRequest.AddBody(upload_stream,     TRESTContentType.ctAPPLICATION_OCTET_STREAM);
  
  try
    RESTRequest.Execute;//Exception line
  except
  on e: Exception do
  begin
    ShowMessage(e.Message);
     end;
         end;
    upload_stream.Free;
  </code></pre>
  
  <p><strong>Edit:</strong> </p>
  
  <p>Finally I was able to upload a file to google drive. I changed the api url which previously I set it as <code>LURL := LURL + '&amp;scope=' + URIEncode('https://www.googleapis.com/auth/tasks')</code>. I changed it to <code>LURL := LURL + '&amp;scope=' + URIEncode('https://www.googleapis.com/auth/drive')</code> and now the file is getting uploaded properly.</p>
  
  <p>Everything seemed good. But I noticed that the file is getting uploaded with untitled file name as in the below image.</p>
  
  <p><a href="https://i.stack.imgur.com/5eHej.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5eHej.png" alt="enter image description here"></a> </p>
  
  <p>Can some one suggest how to give a file name/ upload the file with the same name to google drive.</p>