title: uploading files to onedrive using delphi rest api
body: <p>Access token getting added to content of the text file while uploading file to onedrive using rest api in delphi. How to remove access token from Content of text file that i uploaded.</p>
  
  <p>my observations.</p>
  
  <p>1.If i see my request in fiddler access token is getting added to body of the content(even though i cleared body after authenticate method called)</p>
  
  <p>2.If i put TRESTContentType as ct_None then i can see two content dispositions are going in reqest.one is file content and the other is Access token.</p>
  
  <p>3.I even tried to remove extra content by overriding content length value which resulted in protocol violation exception.</p>
  
  <p>4.If i remove access token from request i am getting unauthorized access(which is obvious)</p>
  
  <p>Please help me.
  //
  _filename :=  'C:\filename.txt';</p>
  
  <pre><code>  RClient := TRESTClient.Create('https://api.onedrive.com/v1.0'); 
    RClient .Authenticator :=OAuth2_OneDrive ;
  
    RESTRequest.Params.Clear;
    RESTRequest.ClearBody;
    RESTRequest.Method := TRestRequestMethod.rmPUT;
    RESTRequest.Resource:='/drive/items/root:/newFile.txt:/content';
  
    RESTRequest.Client:= RClient ;
  
    RESTRequest.AddAuthParameter('Authorization', 'Bearer ' + OAuth2_OneDrive.AccessToken, TRESTRequestParameterKind.pkHTTPHEADER, [TRESTRequestParameterOption.poDoNotEncode]);
  
    upload_stream := TFileStream.Create(_filename ,fmOpenRead);
    upload_stream.Position := 0;
  
    Size := upload_stream.Size- upload_stream.Position;
    SetLength(Buffer, Size);
    upload_stream.ReadBuffer(Pointer(Buffer)^, Size);
  
    Size := TEncoding.GetBufferEncoding(Buffer, Encoding);
    TextDocText := Encoding.GetString(Buffer, Size, Length(Buffer) - Size);
  
    RESTClient.Authenticator.Authenticate(RESTRequest);
  
    RESTRequest.ClearBody;
  
     RESTRequest.AddBody(TextDocText,TRESTContentType.ctTEXT_PLAIN);
     RESTRequest.Params.AddItem('Cache-Control', 'no-store, no-cache', TRESTRequestParameterKind.pkHTTPHEADER );
  
  
    RESTRequest.Execute;
  </code></pre>