AWS SDK for C++

AWS SDK for C++ Version 1.11.440

Loading...
Searching...
No Matches
TransferManager.h
1
6#pragma once
7
8#include <aws/transfer/TransferHandle.h>
9#include <aws/s3/S3Client.h>
10#include <aws/s3/model/PutObjectRequest.h>
11#include <aws/s3/model/GetObjectRequest.h>
12#include <aws/s3/model/HeadObjectRequest.h>
13#include <aws/s3/model/CreateMultipartUploadRequest.h>
14#include <aws/s3/model/UploadPartRequest.h>
15#include <aws/s3/model/CompletedPart.h>
16#include <aws/core/utils/threading/Executor.h>
17#include <aws/core/utils/memory/stl/AWSStreamFwd.h>
18#include <aws/core/utils/ResourceManager.h>
19#include <aws/core/client/AsyncCallerContext.h>
20
21#include <memory>
22
23namespace Aws
24{
25 namespace Transfer
26 {
27 class TransferManager;
28
29 typedef std::function<void(const TransferManager*, const std::shared_ptr<const TransferHandle>&)> UploadProgressCallback;
30 typedef std::function<void(const TransferManager*, const std::shared_ptr<const TransferHandle>&)> DownloadProgressCallback;
31 typedef std::function<void(const TransferManager*, const std::shared_ptr<const TransferHandle>&)> TransferStatusUpdatedCallback;
32 typedef std::function<void(const TransferManager*, const std::shared_ptr<const TransferHandle>&, const Aws::Client::AWSError<Aws::S3::S3Errors>&)> ErrorCallback;
33 typedef std::function<void(const TransferManager*, const std::shared_ptr<const TransferHandle>&)> TransferInitiatedCallback;
34
35 const uint64_t MB5 = 5 * 1024 * 1024;
36
41 {
43 : s3Client(nullptr),
44 transferExecutor(executor),
45 computeContentMD5(false),
48 {
49 }
53 std::shared_ptr<Aws::S3::S3Client> s3Client;
60
65 std::shared_ptr<Aws::Utils::Threading::Executor> spExecutor = nullptr;
66
70 std::function<std::shared_ptr<Utils::Threading::Executor>()> executorCreateFn;
71
77 bool computeContentMD5 = false;
113 uint64_t bufferSize = MB5;
114
142
148 Aws::S3::Model::ChecksumAlgorithm checksumAlgorithm = S3::Model::ChecksumAlgorithm::CRC32;
149 };
150
157 class AWS_TRANSFER_API TransferManager : public std::enable_shared_from_this<TransferManager>
158 {
159 public:
163 static std::shared_ptr<TransferManager> Create(const TransferManagerConfiguration& config);
164
173 TransferStatus WaitUntilAllFinished(int64_t timeoutMs = std::numeric_limits<int64_t>::max());
174
179 void CancelAll();
180
182
188 std::shared_ptr<TransferHandle> UploadFile(const Aws::String& fileName,
189 const Aws::String& bucketName,
190 const Aws::String& keyName,
191 const Aws::String& contentType,
193 const std::shared_ptr<const Aws::Client::AsyncCallerContext>& context = nullptr);
194
199 std::shared_ptr<TransferHandle> UploadFile(const std::shared_ptr<Aws::IOStream>& stream,
200 const Aws::String& bucketName,
201 const Aws::String& keyName,
202 const Aws::String& contentType,
204 const std::shared_ptr<const Aws::Client::AsyncCallerContext>& context = nullptr);
205
209 std::shared_ptr<TransferHandle> DownloadFile(const Aws::String& bucketName,
210 const Aws::String& keyName,
211 const Aws::String& writeToFile,
212 const DownloadConfiguration& downloadConfig = DownloadConfiguration(),
213 const std::shared_ptr<const Aws::Client::AsyncCallerContext>& context = nullptr);
217 std::shared_ptr<TransferHandle> DownloadFile(const Aws::String& bucketName,
218 const Aws::String& keyName,
219 CreateDownloadStreamCallback writeToStreamfn,
220 const DownloadConfiguration& downloadConfig = DownloadConfiguration(),
221 const Aws::String& writeToFile = "",
222 const std::shared_ptr<const Aws::Client::AsyncCallerContext>& context = nullptr);
223
227 std::shared_ptr<TransferHandle> DownloadFile(const Aws::String& bucketName,
228 const Aws::String& keyName,
229 uint64_t fileOffset,
230 uint64_t downloadBytes,
231 CreateDownloadStreamCallback writeToStreamfn,
232 const DownloadConfiguration& downloadConfig = DownloadConfiguration(),
233 const Aws::String& writeToFile = "",
234 const std::shared_ptr<const Aws::Client::AsyncCallerContext>& context = nullptr);
235
239 std::shared_ptr<TransferHandle> RetryDownload(const std::shared_ptr<TransferHandle>& retryHandle);
240
244 std::shared_ptr<TransferHandle> RetryUpload(const Aws::String& fileName, const std::shared_ptr<TransferHandle>& retryHandle);
248 std::shared_ptr<TransferHandle> RetryUpload(const std::shared_ptr<Aws::IOStream>& stream, const std::shared_ptr<TransferHandle>& retryHandle);
249
255 void AbortMultipartUpload(const std::shared_ptr<TransferHandle>& inProgressHandle);
256
266 void UploadDirectory(const Aws::String& directory, const Aws::String& bucketName, const Aws::String& prefix, const Aws::Map<Aws::String, Aws::String>& metadata);
267
277 void DownloadToDirectory(const Aws::String& directory, const Aws::String& bucketName, const Aws::String& prefix = Aws::String());
278
279 private:
284
289 std::shared_ptr<TransferHandle> CreateUploadFileHandle(Aws::IOStream* fileStream,
290 const Aws::String& bucketName,
291 const Aws::String& keyName,
292 const Aws::String& contentType,
293 const Aws::Map<Aws::String,
294 Aws::String>& metadata,
295 const std::shared_ptr<const Aws::Client::AsyncCallerContext>& context,
296 const Aws::String& fileName = "");
297
301 std::shared_ptr<TransferHandle> SubmitUpload(const std::shared_ptr<TransferHandle>& handle, const std::shared_ptr<Aws::IOStream>& fileStream = nullptr);
302
303 bool MultipartUploadSupported(uint64_t length) const;
304 bool InitializePartsForDownload(const std::shared_ptr<TransferHandle>& handle);
305
306 void DoMultiPartUpload(const std::shared_ptr<Aws::IOStream>& streamToPut, const std::shared_ptr<TransferHandle>& handle);
307 void DoSinglePartUpload(const std::shared_ptr<Aws::IOStream>& streamToPut, const std::shared_ptr<TransferHandle>& handle);
308
309 void DoMultiPartUpload(const std::shared_ptr<TransferHandle>& handle);
310 void DoSinglePartUpload(const std::shared_ptr<TransferHandle>& handle);
311
312 void DoDownload(const std::shared_ptr<TransferHandle>& handle);
313 void DoSinglePartDownload(const std::shared_ptr<TransferHandle>& handle);
314
315 void HandleGetObjectResponse(const Aws::S3::S3Client* client,
317 const Aws::S3::Model::GetObjectOutcome& outcome,
318 const std::shared_ptr<const Aws::Client::AsyncCallerContext>& context);
319
320 void WaitForCancellationAndAbortUpload(const std::shared_ptr<TransferHandle>& canceledHandle);
321
322 void HandleUploadPartResponse(const Aws::S3::S3Client*, const Aws::S3::Model::UploadPartRequest&, const Aws::S3::Model::UploadPartOutcome&, const std::shared_ptr<const Aws::Client::AsyncCallerContext>&);
323 void HandlePutObjectResponse(const Aws::S3::S3Client*, const Aws::S3::Model::PutObjectRequest&, const Aws::S3::Model::PutObjectOutcome&, const std::shared_ptr<const Aws::Client::AsyncCallerContext>&);
324 void HandleListObjectsResponse(const Aws::S3::S3Client*, const Aws::S3::Model::ListObjectsV2Request&, const Aws::S3::Model::ListObjectsV2Outcome&, const std::shared_ptr<const Aws::Client::AsyncCallerContext>&);
325
326 TransferStatus DetermineIfFailedOrCanceled(const TransferHandle&) const;
327 void TriggerUploadProgressCallback(const std::shared_ptr<const TransferHandle>&) const;
328 void TriggerDownloadProgressCallback(const std::shared_ptr<const TransferHandle>&) const;
329 void TriggerTransferStatusUpdatedCallback(const std::shared_ptr<const TransferHandle>&) const;
330 void TriggerErrorCallback(const std::shared_ptr<const TransferHandle>&, const Aws::Client::AWSError<Aws::S3::S3Errors>& error)const;
331
336 void AddTask(std::shared_ptr<TransferHandle> handle);
337 void RemoveTask(const std::shared_ptr<TransferHandle>& handle);
338
344 void SetChecksumForAlgorithm(const std::shared_ptr<PartState> state, Aws::S3::Model::CompletedPart &part);
345
346 static Aws::String DetermineFilePath(const Aws::String& directory, const Aws::String& prefix, const Aws::String& keyName);
347
349 TransferManagerConfiguration m_transferConfig;
350
352 mutable std::condition_variable m_tasksSignal;
353 mutable std::mutex m_tasksMutex;
354
355 protected:
356 static bool IsWithinParentDirectory(Aws::String parentDirectory, Aws::String filePath);
357 };
358
359
360 }
361}
TransferStatus WaitUntilAllFinished(int64_t timeoutMs=std::numeric_limits< int64_t >::max())
std::shared_ptr< TransferHandle > DownloadFile(const Aws::String &bucketName, const Aws::String &keyName, const Aws::String &writeToFile, const DownloadConfiguration &downloadConfig=DownloadConfiguration(), const std::shared_ptr< const Aws::Client::AsyncCallerContext > &context=nullptr)
void UploadDirectory(const Aws::String &directory, const Aws::String &bucketName, const Aws::String &prefix, const Aws::Map< Aws::String, Aws::String > &metadata)
std::shared_ptr< TransferHandle > DownloadFile(const Aws::String &bucketName, const Aws::String &keyName, uint64_t fileOffset, uint64_t downloadBytes, CreateDownloadStreamCallback writeToStreamfn, const DownloadConfiguration &downloadConfig=DownloadConfiguration(), const Aws::String &writeToFile="", const std::shared_ptr< const Aws::Client::AsyncCallerContext > &context=nullptr)
std::shared_ptr< TransferHandle > RetryUpload(const Aws::String &fileName, const std::shared_ptr< TransferHandle > &retryHandle)
std::shared_ptr< TransferHandle > DownloadFile(const Aws::String &bucketName, const Aws::String &keyName, CreateDownloadStreamCallback writeToStreamfn, const DownloadConfiguration &downloadConfig=DownloadConfiguration(), const Aws::String &writeToFile="", const std::shared_ptr< const Aws::Client::AsyncCallerContext > &context=nullptr)
std::shared_ptr< TransferHandle > RetryUpload(const std::shared_ptr< Aws::IOStream > &stream, const std::shared_ptr< TransferHandle > &retryHandle)
std::shared_ptr< TransferHandle > RetryDownload(const std::shared_ptr< TransferHandle > &retryHandle)
std::shared_ptr< TransferHandle > UploadFile(const Aws::String &fileName, const Aws::String &bucketName, const Aws::String &keyName, const Aws::String &contentType, const Aws::Map< Aws::String, Aws::String > &metadata, const std::shared_ptr< const Aws::Client::AsyncCallerContext > &context=nullptr)
void AbortMultipartUpload(const std::shared_ptr< TransferHandle > &inProgressHandle)
static bool IsWithinParentDirectory(Aws::String parentDirectory, Aws::String filePath)
static std::shared_ptr< TransferManager > Create(const TransferManagerConfiguration &config)
void DownloadToDirectory(const Aws::String &directory, const Aws::String &bucketName, const Aws::String &prefix=Aws::String())
std::shared_ptr< TransferHandle > UploadFile(const std::shared_ptr< Aws::IOStream > &stream, const Aws::String &bucketName, const Aws::String &keyName, const Aws::String &contentType, const Aws::Map< Aws::String, Aws::String > &metadata, const std::shared_ptr< const Aws::Client::AsyncCallerContext > &context=nullptr)
std::function< void(const TransferManager *, const std::shared_ptr< const TransferHandle > &, const Aws::Client::AWSError< Aws::S3::S3Errors > &)> ErrorCallback
const uint64_t MB5
std::function< void(const TransferManager *, const std::shared_ptr< const TransferHandle > &)> TransferStatusUpdatedCallback
std::function< void(const TransferManager *, const std::shared_ptr< const TransferHandle > &)> DownloadProgressCallback
std::function< void(const TransferManager *, const std::shared_ptr< const TransferHandle > &)> UploadProgressCallback
std::function< void(const TransferManager *, const std::shared_ptr< const TransferHandle > &)> TransferInitiatedCallback
std::function< Aws::IOStream *(void)> CreateDownloadStreamCallback
std::map< K, V, std::less< K >, Aws::Allocator< std::pair< const K, V > > > Map
std::basic_iostream< char, std::char_traits< char > > IOStream
std::unordered_set< T, std::hash< T >, std::equal_to< T >, Aws::Allocator< T > > UnorderedSet
std::basic_string< char, std::char_traits< char >, Aws::Allocator< char > > String
Aws::S3::Model::CreateMultipartUploadRequest createMultipartUploadTemplate
Aws::Utils::Threading::Executor * transferExecutor
Aws::S3::Model::GetObjectRequest getObjectTemplate
std::shared_ptr< Aws::S3::S3Client > s3Client
DownloadProgressCallback downloadProgressCallback
TransferStatusUpdatedCallback transferStatusUpdatedCallback
Aws::S3::Model::ChecksumAlgorithm checksumAlgorithm
Aws::Map< Aws::String, Aws::String > customizedAccessLogTag
Aws::S3::Model::UploadPartRequest uploadPartTemplate
std::function< std::shared_ptr< Utils::Threading::Executor >()> executorCreateFn
std::shared_ptr< Aws::Utils::Threading::Executor > spExecutor
TransferInitiatedCallback transferInitiatedCallback
Aws::S3::Model::HeadObjectRequest headObjectTemplate
Aws::S3::Model::PutObjectRequest putObjectTemplate
TransferManagerConfiguration(Aws::Utils::Threading::Executor *executor)