how to upload file to dropbox via Delphi 7?

后端 未结 2 1533
刺人心
刺人心 2020-12-30 13:56

I try to upload file into dropbox.
I use dropbox api https://www.dropbox.com/developers/reference/api#files-POST

procedure TDropbox.Upload2;
const
  UR         


        
相关标签:
2条回答
  • 2020-12-30 14:38
    1. Use %26 instead & in oauth_signature parameter. There is two values in one parameter concated by & symbol.
    2. Pass file via TMemoryStream.

      procedure TDropbox.Upload(const AFileName: String);
      const
        API_URL = 'https://api-content.dropbox.com/1/files_put/sandbox/';
      var
        URL: String;
        Stream: TMemoryStream;
        ShortFileName: String;
        https: TIdHTTP;
        SslIoHandler: TIdSSLIOHandlerSocket;
      begin
        if not FileExists(AFileName) then
        begin
          raise EInOutError.CreateFmt('File %s not found', [AFileName]);
        end;
      
        ShortFileName := ExtractFileName(AFileName);
        URL := API_URL+ShortFileName
          + '?oauth_signature_method=PLAINTEXT&oauth_consumer_key=' + FAppKey
          + '&oauth_token=' + FOAuth.AccessToken
          + '&oauth_signature=' + FAppSecret + '%26' + FOAuth.AccessTokenSecret;
      
        https := TIdHTTP.Create(nil);
        Stream := TMemoryStream.Create;
        try
          SslIoHandler := TIdSSLIOHandlerSocket.Create(https);
          SslIoHandler.SSLOptions.Method := sslvTLSv1;
          SslIoHandler.SSLOptions.Mode := sslmUnassigned;
      
          https.IOHandler := SslIoHandler;
          Stream.LoadFromFile(AFileName);
      
          https.Post(URL, Stream);
        finally
          FreeAndNil(Stream);
          FreeAndNil(https);
        end;
      end;
      
    0 讨论(0)
  • 2020-12-30 14:45

    Try this instead:

    procedure TDropbox.Upload(const AFileName: String);
    const
      API_URL = 'https://api-content.dropbox.com/1/files_put/sandbox/';
    var
      URL: String;
      https: TIdHTTP;
      SslIoHandler: TIdSSLIOHandlerSocket;
    begin
      URL := API_URL+ExtractFileName(AFileName)
        + '?oauth_signature_method=PLAINTEXT&oauth_consumer_key=' + FAppKey
        + '&oauth_token=' + FOAuth.AccessToken
        + '&oauth_signature=' + FAppSecret + '%26' + FOAuth.AccessTokenSecret;
    
      https := TIdHTTP.Create(nil);
      try
        SslIoHandler := TIdSSLIOHandlerSocket.Create(https);
        SslIoHandler.SSLOptions.Method := sslvTLSv1;
        SslIoHandler.SSLOptions.Mode := sslmUnassigned;
    
        https.IOHandler := SslIoHandler;
        https.Post(URL, AFileName);
      finally
        FreeAndNil(https);
      end;
    end;
    
    0 讨论(0)
提交回复
热议问题