-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathAWS4D.S3.Get.pas
More file actions
105 lines (90 loc) · 2.47 KB
/
Copy pathAWS4D.S3.Get.pas
File metadata and controls
105 lines (90 loc) · 2.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
unit AWS4D.S3.Get;
interface
uses
AWS4D.Interfaces;
type
TAWS4DS3GetFile = class(TInterfacedObject, iAWS4DS3GetFile)
private
[weak]
FParent : iAWS4DS3;
FFileName : String;
FContentType : String;
public
constructor Create( aParent : iAWS4DS3);
destructor Destroy; override;
class function New ( aParent : iAWS4DS3) : iAWS4DS3GetFile;
function FileName ( aValue : String ) : iAWS4DS3GetFile;
function ContentType( aValue : String ) : iAWS4DS3GetFile;
function Get : iAWS4DS3;
end;
implementation
uses
System.Classes,
System.StrUtils,
Data.Cloud.AmazonAPI,
Data.Cloud.CloudAPI,
System.SysUtils,
{$IF CompilerVersion > 22}
Vcl.Imaging.jpeg;
{$ELSE}
jpeg;
{$IFEND}
{ TBind4DAmazonS3Get }
function TAWS4DS3GetFile.ContentType(aValue: String): iAWS4DS3GetFile;
begin
Result := Self;
FContentType := aValue;
end;
constructor TAWS4DS3GetFile.Create(aParent: iAWS4DS3);
begin
FParent := aParent;
end;
destructor TAWS4DS3GetFile.Destroy;
begin
inherited;
end;
function TAWS4DS3GetFile.FileName(aValue: String): iAWS4DS3GetFile;
begin
Result := Self;
FFileName := aValue;
end;
function TAWS4DS3GetFile.Get: iAWS4DS3;
var
AmazonConnectionInfo1: TAmazonConnectionInfo;
StorageService : TAmazonStorageService;
CloudResponse : TCloudResponseInfo;
begin
Result := FParent;
AmazonConnectionInfo1 := TAmazonConnectionInfo.Create(nil);
StorageService := TAmazonStorageService.Create(AmazonConnectionInfo1);
CloudResponse := TCloudResponseInfo.Create;
FFileName := ReverseString(FFileName);
FFileName := Copy(FFileName, 0, Pos('/', FFileName)-1);
FFileName := ReverseString(FFileName);
try
if Trim(FFileName) <> '' then
begin
AmazonConnectionInfo1.AccountKey := FParent.&End.Credential.AccountKey;
AmazonConnectionInfo1.AccountName := FParent.&End.Credential.AccountName;
AmazonConnectionInfo1.StorageEndpoint := FParent.&End.Credential.StorageEndPoint;
AmazonConnectionInfo1.UseDefaultEndpoints := False;
if not StorageService.GetObject(
FParent.&End.Credential.Bucket,
FFileName,
FParent.ContentByteStream,
CloudResponse
) then
raise Exception.Create(CloudResponse.StatusMessage);
end;
finally
CloudResponse.Free;
StorageService.Free;
AmazonConnectionInfo1.Free;
end;
end;
class function TAWS4DS3GetFile.New(
aParent: iAWS4DS3): iAWS4DS3GetFile;
begin
Result := Self.Create(aParent);
end;
end.