我需要以編程方式請求一些檔案并將檔案作為回應發送。如何通過 API 從 Delphi 創建檔案請求(https://www.dropbox.com/requests),以便第 3 方可以使用這種代碼將請求的檔案發回給我;
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;
uj5u.com熱心網友回復:
您帖子中的代碼參考了一個 API 端點,用于使用已停用的 Dropbox API v1 上傳檔案。
如果您希望以編程方式創建檔案請求,則應改用當前 Dropbox API v2 上的 /2/file_requests/create 端點。您可以在此處找到相關檔案:
https://www.dropbox.com/developers/documentation/http/documentation#file_requests-create
請注意,Dropbox API 不提供以編程方式將檔案上傳到檔案請求的功能。您可以如上所述以編程方式創建檔案請求,但上傳到檔案請求將是一個手動程序。
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/517053.html
