I need to programmatically request some files and send files as a response. How can I create a file request ( https://www.dropbox.com/requests ) from Delphi through API so that 3rd parties can send requested files back to me with this kind of code;
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 '&' 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;
CodePudding user response:
The code in your post references an API endpoint for uploading files using the retired Dropbox API v1.
If you wish to programmatically create file requests, you should instead use the /2/file_requests/create endpoint on the current Dropbox API v2. You can find the documentation for that here:
https://www.dropbox.com/developers/documentation/http/documentation#file_requests-create
Note that the Dropbox API does not offer the ability to programmatically upload a file to a file request. You can create the file request programmatically as above, but uploading to the file request would be a manual process.