C++Builder を使って AWS S3に接続[JAPAN]
[AWS S3 接続]
Delphi/C++ Builderは Cloudを得意とする複数のコンポーネントがあり
AWS接続のためのTAmazonConnectionInfoコンポーネントも用意されています
Amazon Web Services(AWS) のストレージサービスであるSimple Storage Service(S3)をC++Builderから接続します。
[S3 Bucketを用意します]
embarcadero-jpと言う名前でBucketを作成しました。
[TAmazonConnectionInfo配置と設定]
TAmazonConnectionInfoを配置します
AccountKey、AccountNameプロパティをIAMと同じ内容を設定します。
[Bucket内のリストを取得する](code example)
//// void __fastcall TForm1::Button1Click(TObject *Sender) { std::unique_ptr<TStringList> list_{new TStringList() }; std::unique_ptr<TAmazonStorageService> s3{new TAmazonStorageService(AmazonConnectionInfo1)}; TCloudResponseInfo* res_{new TCloudResponseInfo()}; try { TAmazonBucketResult* bs = s3->GetBucket("embarcadero-jp", list_.get(), res_, TAmazonRegion::amzrAPNortheast1); Memo1->Lines->Text = list_->Text; for (auto obj_:bs->Objects) { Memo1->Lines->Append(obj_.Name + " size=" + (String)obj_.Size); } } __finally { delete res_; } }
[バイナリデータ UploadObject / GetObject](code example)
//// void __fastcall TForm1::Button1Click(TObject *Sender) { std::unique_ptr<TStringList> list_{new TStringList() }; std::unique_ptr<TAmazonStorageService> s3{new TAmazonStorageService(AmazonConnectionInfo1)}; TCloudResponseInfo* res_{new TCloudResponseInfo()}; try { std::unique_ptr<TMemoryStream> mm{new TMemoryStream()}; mm->LoadFromFile("C:\\Embarcadero\\devcam33\\AWS_S3_cpp\\amane-phone.jpg"); DynamicArray<Byte> arr1; arr1.Length = mm->Size; mm->ReadBuffer(arr1, mm->Size); mm->Position = 0; s3->UploadObject("embarcadero-jp", "amane-phone.jpg", arr1, true, nullptr, nullptr, TAmazonACLType::amzbaPublicRead, res_); mm->Clear(); TAmazonGetObjectOptionals* op_{new TAmazonGetObjectOptionals()}; s3->GetObject( "embarcadero-jp", "amane-phone.jpg", mm.get(), res_); Image1->Bitmap->LoadFromStream(mm.get()); } __finally { delete res_; } }
GetObjectでデータがTStreamで返ってきますので
Image1->Bitmap->LoadFromStream(mm.get());としています
Video not found or Youtube service not available


Delphi / C++Builder blogger
Comments
-
Please login first in order for you to submit comments