AWS SDK for C++  1.9.40
AWS SDK for C++
TransferManager.h
Go to the documentation of this file.
1 
6 #pragma once
7 
9 #include <aws/s3/S3Client.h>
18 
19 #include <memory>
20 
21 namespace Aws
22 {
23  namespace Transfer
24  {
25  class TransferManager;
26 
27  typedef std::function<void(const TransferManager*, const std::shared_ptr<const TransferHandle>&)> UploadProgressCallback;
28  typedef std::function<void(const TransferManager*, const std::shared_ptr<const TransferHandle>&)> DownloadProgressCallback;
29  typedef std::function<void(const TransferManager*, const std::shared_ptr<const TransferHandle>&)> TransferStatusUpdatedCallback;
30  typedef std::function<void(const TransferManager*, const std::shared_ptr<const TransferHandle>&, const Aws::Client::AWSError<Aws::S3::S3Errors>&)> ErrorCallback;
31  typedef std::function<void(const TransferManager*, const std::shared_ptr<const TransferHandle>&)> TransferInitiatedCallback;
32 
33  const uint64_t MB5 = 5 * 1024 * 1024;
34 
39  {
41  {
42  }
43 
47  std::shared_ptr<Aws::S3::S3Client> s3Client;
90  uint64_t bufferSize;
91 
119  };
120 
127  class AWS_TRANSFER_API TransferManager : public std::enable_shared_from_this<TransferManager>
128  {
129  public:
133  static std::shared_ptr<TransferManager> Create(const TransferManagerConfiguration& config);
134 
136 
141  std::shared_ptr<TransferHandle> UploadFile(const Aws::String& fileName,
142  const Aws::String& bucketName,
143  const Aws::String& keyName,
144  const Aws::String& contentType,
145  const Aws::Map<Aws::String, Aws::String>& metadata,
146  const std::shared_ptr<const Aws::Client::AsyncCallerContext>& context = nullptr);
147 
152  std::shared_ptr<TransferHandle> UploadFile(const std::shared_ptr<Aws::IOStream>& stream,
153  const Aws::String& bucketName,
154  const Aws::String& keyName,
155  const Aws::String& contentType,
156  const Aws::Map<Aws::String, Aws::String>& metadata,
157  const std::shared_ptr<const Aws::Client::AsyncCallerContext>& context = nullptr);
158 
162  std::shared_ptr<TransferHandle> DownloadFile(const Aws::String& bucketName,
163  const Aws::String& keyName,
164  const Aws::String& writeToFile,
165  const DownloadConfiguration& downloadConfig = DownloadConfiguration(),
166  const std::shared_ptr<const Aws::Client::AsyncCallerContext>& context = nullptr);
170  std::shared_ptr<TransferHandle> DownloadFile(const Aws::String& bucketName,
171  const Aws::String& keyName,
172  CreateDownloadStreamCallback writeToStreamfn,
173  const DownloadConfiguration& downloadConfig = DownloadConfiguration(),
174  const Aws::String& writeToFile = "",
175  const std::shared_ptr<const Aws::Client::AsyncCallerContext>& context = nullptr);
176 
180  std::shared_ptr<TransferHandle> DownloadFile(const Aws::String& bucketName,
181  const Aws::String& keyName,
182  uint64_t fileOffset,
183  uint64_t downloadBytes,
184  CreateDownloadStreamCallback writeToStreamfn,
185  const DownloadConfiguration& downloadConfig = DownloadConfiguration(),
186  const Aws::String& writeToFile = "",
187  const std::shared_ptr<const Aws::Client::AsyncCallerContext>& context = nullptr);
188 
192  std::shared_ptr<TransferHandle> RetryDownload(const std::shared_ptr<TransferHandle>& retryHandle);
193 
197  std::shared_ptr<TransferHandle> RetryUpload(const Aws::String& fileName, const std::shared_ptr<TransferHandle>& retryHandle);
201  std::shared_ptr<TransferHandle> RetryUpload(const std::shared_ptr<Aws::IOStream>& stream, const std::shared_ptr<TransferHandle>& retryHandle);
202 
208  void AbortMultipartUpload(const std::shared_ptr<TransferHandle>& inProgressHandle);
209 
219  void UploadDirectory(const Aws::String& directory, const Aws::String& bucketName, const Aws::String& prefix, const Aws::Map<Aws::String, Aws::String>& metadata);
220 
230  void DownloadToDirectory(const Aws::String& directory, const Aws::String& bucketName, const Aws::String& prefix = Aws::String());
231 
232  private:
237 
242  std::shared_ptr<TransferHandle> CreateUploadFileHandle(Aws::IOStream* fileStream,
243  const Aws::String& bucketName,
244  const Aws::String& keyName,
245  const Aws::String& contentType,
246  const Aws::Map<Aws::String,
247  Aws::String>& metadata,
248  const std::shared_ptr<const Aws::Client::AsyncCallerContext>& context,
249  const Aws::String& fileName = "");
250 
254  std::shared_ptr<TransferHandle> SubmitUpload(const std::shared_ptr<TransferHandle>& handle, const std::shared_ptr<Aws::IOStream>& fileStream = nullptr);
255 
260  std::shared_ptr<TransferHandle> DoUploadFile(const std::shared_ptr<Aws::IOStream>& fileStream,
261  const Aws::String& bucketName,
262  const Aws::String& keyName,
263  const Aws::String& contentType,
264  const Aws::Map<Aws::String, Aws::String>& metadata,
265  const std::shared_ptr<const Aws::Client::AsyncCallerContext>& context);
266 
272  std::shared_ptr<TransferHandle> DoUploadFile(const Aws::String& fileName,
273  const Aws::String& bucketName,
274  const Aws::String& keyName,
275  const Aws::String& contentType,
276  const Aws::Map<Aws::String, Aws::String>& metadata,
277  const std::shared_ptr<const Aws::Client::AsyncCallerContext>& context);
278 
279  bool MultipartUploadSupported(uint64_t length) const;
280  bool InitializePartsForDownload(const std::shared_ptr<TransferHandle>& handle);
281 
282  void DoMultiPartUpload(const std::shared_ptr<Aws::IOStream>& streamToPut, const std::shared_ptr<TransferHandle>& handle);
283  void DoSinglePartUpload(const std::shared_ptr<Aws::IOStream>& streamToPut, const std::shared_ptr<TransferHandle>& handle);
284 
285  void DoMultiPartUpload(const std::shared_ptr<TransferHandle>& handle);
286  void DoSinglePartUpload(const std::shared_ptr<TransferHandle>& handle);
287 
288  void DoDownload(const std::shared_ptr<TransferHandle>& handle);
289  void DoSinglePartDownload(const std::shared_ptr<TransferHandle>& handle);
290 
291  void HandleGetObjectResponse(const Aws::S3::S3Client* client,
292  const Aws::S3::Model::GetObjectRequest& request,
293  const Aws::S3::Model::GetObjectOutcome& outcome,
294  const std::shared_ptr<const Aws::Client::AsyncCallerContext>& context);
295 
296  void WaitForCancellationAndAbortUpload(const std::shared_ptr<TransferHandle>& canceledHandle);
297 
298  void HandleUploadPartResponse(const Aws::S3::S3Client*, const Aws::S3::Model::UploadPartRequest&, const Aws::S3::Model::UploadPartOutcome&, const std::shared_ptr<const Aws::Client::AsyncCallerContext>&);
299  void HandlePutObjectResponse(const Aws::S3::S3Client*, const Aws::S3::Model::PutObjectRequest&, const Aws::S3::Model::PutObjectOutcome&, const std::shared_ptr<const Aws::Client::AsyncCallerContext>&);
300  void HandleListObjectsResponse(const Aws::S3::S3Client*, const Aws::S3::Model::ListObjectsV2Request&, const Aws::S3::Model::ListObjectsV2Outcome&, const std::shared_ptr<const Aws::Client::AsyncCallerContext>&);
301 
302  TransferStatus DetermineIfFailedOrCanceled(const TransferHandle&) const;
303  void TriggerUploadProgressCallback(const std::shared_ptr<const TransferHandle>&) const;
304  void TriggerDownloadProgressCallback(const std::shared_ptr<const TransferHandle>&) const;
305  void TriggerTransferStatusUpdatedCallback(const std::shared_ptr<const TransferHandle>&) const;
306  void TriggerErrorCallback(const std::shared_ptr<const TransferHandle>&, const Aws::Client::AWSError<Aws::S3::S3Errors>& error)const;
307 
308  static Aws::String DetermineFilePath(const Aws::String& directory, const Aws::String& prefix, const Aws::String& keyName);
309 
311  TransferManagerConfiguration m_transferConfig;
312  };
313 
314 
315  }
316 }
Aws::Transfer::TransferManager::RetryUpload
std::shared_ptr< TransferHandle > RetryUpload(const Aws::String &fileName, const std::shared_ptr< TransferHandle > &retryHandle)
Aws::Transfer::UploadProgressCallback
std::function< void(const TransferManager *, const std::shared_ptr< const TransferHandle > &)> UploadProgressCallback
Definition: TransferManager.h:25
Aws::IOStream
std::basic_iostream< char, std::char_traits< char > > IOStream
Definition: AWSStreamFwd.h:22
Aws::Transfer::TransferStatusUpdatedCallback
std::function< void(const TransferManager *, const std::shared_ptr< const TransferHandle > &)> TransferStatusUpdatedCallback
Definition: TransferManager.h:29
TransferHandle.h
Aws::Transfer::TransferManager::DownloadFile
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)
Aws::Transfer::TransferInitiatedCallback
std::function< void(const TransferManager *, const std::shared_ptr< const TransferHandle > &)> TransferInitiatedCallback
Definition: TransferManager.h:31
Aws::S3::Model::CreateMultipartUploadRequest
Definition: CreateMultipartUploadRequest.h:34
Aws::Transfer::TransferManagerConfiguration::errorCallback
ErrorCallback errorCallback
Definition: TransferManager.h:111
S3Client.h
Aws::Transfer::TransferManagerConfiguration::transferInitiatedCallback
TransferInitiatedCallback transferInitiatedCallback
Definition: TransferManager.h:107
Aws::Transfer::MB5
const uint64_t MB5
Definition: TransferManager.h:33
Aws::Transfer::TransferManager
Definition: TransferManager.h:128
Aws::Transfer::TransferManagerConfiguration::transferBufferMaxHeapSize
uint64_t transferBufferMaxHeapSize
Definition: TransferManager.h:85
Aws::S3::Model::PutObjectRequest
Definition: PutObjectRequest.h:35
Aws::S3::S3Client
Definition: S3Client.h:519
ResourceManager.h
CreateMultipartUploadRequest.h
AWSStreamFwd.h
AsyncCallerContext.h
Aws::Utils::Threading::Executor
Definition: Executor.h:31
Aws::Transfer::TransferManagerConfiguration::createMultipartUploadTemplate
Aws::S3::Model::CreateMultipartUploadRequest createMultipartUploadTemplate
Definition: TransferManager.h:74
Aws::Transfer::TransferManagerConfiguration::transferStatusUpdatedCallback
TransferStatusUpdatedCallback transferStatusUpdatedCallback
Definition: TransferManager.h:103
Aws::S3::Model::ListObjectsV2Request
Definition: ListObjectsV2Request.h:29
Aws::Transfer::TransferManagerConfiguration::customizedAccessLogTag
Aws::Map< Aws::String, Aws::String > customizedAccessLogTag
Definition: TransferManager.h:118
Aws::Transfer::DownloadProgressCallback
std::function< void(const TransferManager *, const std::shared_ptr< const TransferHandle > &)> DownloadProgressCallback
Definition: TransferManager.h:28
Aws::Utils::ExclusiveOwnershipResourceManager< unsigned char * >
Aws::Transfer::CreateDownloadStreamCallback
std::function< Aws::IOStream *(void)> CreateDownloadStreamCallback
Definition: TransferHandle.h:30
Aws::Transfer::DownloadConfiguration
Definition: TransferHandle.h:37
Executor.h
Aws::Transfer::TransferManager::RetryDownload
std::shared_ptr< TransferHandle > RetryDownload(const std::shared_ptr< TransferHandle > &retryHandle)
Aws::Transfer::TransferManagerConfiguration::uploadProgressCallback
UploadProgressCallback uploadProgressCallback
Definition: TransferManager.h:95
UploadPartRequest.h
Aws::Transfer::TransferHandle
Definition: TransferHandle.h:130
Aws::Transfer::TransferManager::UploadFile
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)
Aws::S3::Model::GetObjectRequest
Definition: GetObjectRequest.h:29
Aws::Transfer::TransferManager::DownloadToDirectory
void DownloadToDirectory(const Aws::String &directory, const Aws::String &bucketName, const Aws::String &prefix=Aws::String())
Aws::Client::AWSError< Aws::S3::S3Errors >
Aws::Transfer::TransferManager::RetryUpload
std::shared_ptr< TransferHandle > RetryUpload(const std::shared_ptr< Aws::IOStream > &stream, const std::shared_ptr< TransferHandle > &retryHandle)
Aws::Transfer::TransferManager::DownloadFile
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)
Aws::Transfer::TransferManagerConfiguration::bufferSize
uint64_t bufferSize
Definition: TransferManager.h:90
Aws::Transfer::TransferManager::~TransferManager
~TransferManager()
Aws::S3::Model::UploadPartRequest
Definition: UploadPartRequest.h:29
Aws::Transfer::TransferManager::UploadFile
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)
Aws::Transfer::TransferManager::UploadDirectory
void UploadDirectory(const Aws::String &directory, const Aws::String &bucketName, const Aws::String &prefix, const Aws::Map< Aws::String, Aws::String > &metadata)
Aws
Definition: AccessManagementClient.h:15
Aws::Transfer::TransferManagerConfiguration::transferExecutor
Aws::Utils::Threading::Executor * transferExecutor
Definition: TransferManager.h:53
length
char const int length
Definition: cJSON.h:164
Aws::Transfer::TransferManagerConfiguration::TransferManagerConfiguration
TransferManagerConfiguration(Aws::Utils::Threading::Executor *executor)
Definition: TransferManager.h:40
Aws::Utils::Outcome
Definition: Outcome.h:26
Aws::Transfer::ErrorCallback
std::function< void(const TransferManager *, const std::shared_ptr< const TransferHandle > &, const Aws::Client::AWSError< Aws::S3::S3Errors > &)> ErrorCallback
Definition: TransferManager.h:30
Aws::Transfer::TransferManagerConfiguration::computeContentMD5
bool computeContentMD5
Definition: TransferManager.h:59
Aws::String
std::basic_string< char, std::char_traits< char >, Aws::Allocator< char > > String
Definition: AWSString.h:97
Aws::Transfer::TransferManagerConfiguration
Definition: TransferManager.h:39
Aws::Transfer::TransferManager::DownloadFile
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)
Aws::Transfer::TransferManager::AbortMultipartUpload
void AbortMultipartUpload(const std::shared_ptr< TransferHandle > &inProgressHandle)
Aws::Transfer::TransferManagerConfiguration::downloadProgressCallback
DownloadProgressCallback downloadProgressCallback
Definition: TransferManager.h:99
Aws::Transfer::TransferManagerConfiguration::putObjectTemplate
Aws::S3::Model::PutObjectRequest putObjectTemplate
Definition: TransferManager.h:64
Aws::Transfer::TransferManagerConfiguration::getObjectTemplate
Aws::S3::Model::GetObjectRequest getObjectTemplate
Definition: TransferManager.h:69
Aws::Transfer::TransferManager::Create
static std::shared_ptr< TransferManager > Create(const TransferManagerConfiguration &config)
PutObjectRequest.h
Aws::Map
std::map< K, V, std::less< K >, Aws::Allocator< std::pair< const K, V > > > Map
Definition: AWSMap.h:19
Aws::Transfer::TransferManagerConfiguration::uploadPartTemplate
Aws::S3::Model::UploadPartRequest uploadPartTemplate
Definition: TransferManager.h:79
GetObjectRequest.h
Aws::Transfer::TransferManagerConfiguration::s3Client
std::shared_ptr< Aws::S3::S3Client > s3Client
Definition: TransferManager.h:47
Aws::Transfer::TransferStatus
TransferStatus
Definition: TransferHandle.h:99
AWS_TRANSFER_API
#define AWS_TRANSFER_API
Definition: Transfer_EXPORTS.h:28