AWS SDK for C++  0.12.9
AWS SDK for C++
TransferClient.h
Go to the documentation of this file.
1 
2 /*
3  * Copyright 2010-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License").
6  * You may not use this file except in compliance with the License.
7  * A copy of the License is located at
8  *
9  * http://aws.amazon.com/apache2.0
10  *
11  * or in the "license" file accompanying this file. This file is distributed
12  * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
13  * express or implied. See the License for the specific language governing
14  * permissions and limitations under the License.
15  */
16 
17 #pragma once
18 
19 #ifndef TRANSFER_CLIENT_H
20 #define TRANSFER_CLIENT_H
21 
24 
25 #include <aws/s3/S3Client.h>
26 
27 namespace Aws
28 {
29 namespace S3
30 {
31 
32  namespace Model
33  {
34 
35  } // namespace Model
36 } // namespace S3
37 
38 
39 namespace Transfer
40 {
41 
42 class UploadFileRequest;
43 class DownloadFileRequest;
44 
45 const uint64_t MB5_BUFFER_SIZE = 5 * 1024 * 1024;
46 
48 {
49  public:
50 
53 
55  std::shared_ptr< UploadBufferResourceManagerType > m_uploadBufferManager;
56 };
57 
59 {
60  public:
61  TransferClient(const std::shared_ptr<Aws::S3::S3Client>& s3Client, const TransferClientConfiguration& config);
62  ~TransferClient();
63 
64  // Entry point for attempting an upload - attempting to create an existing bucket won't hurt anything but will affect performance
65  // unnecessarily as the request waits for S3 to propagate the bucket
66  // All queries about the upload after this point can be found in UploadFileRequest's interface
67  std::shared_ptr<UploadFileRequest> UploadFile(const Aws::String& fileName, const Aws::String& bucketName, const Aws::String& keyName, const Aws::String& contentType, bool createBucket = false, bool doConsistencyChecks = false);
68  // Entry point similar to above but with metadata specified
69  std::shared_ptr<UploadFileRequest> 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, bool createBucket = false, bool doConsistencyChecks = false);
70  std::shared_ptr<UploadFileRequest> UploadFile(const Aws::String& fileName, const Aws::String& bucketName, const Aws::String& keyName, const Aws::String& contentType, Aws::Map<Aws::String, Aws::String>&& metadata, bool createBucket = false, bool doConsistencyChecks = false);
71 
72  // User requested upload cancels should go through here
73  void CancelUpload(std::shared_ptr<UploadFileRequest>& fileRequest) const;
74 
75  // Single entry point for attempting a download
76  std::shared_ptr<DownloadFileRequest> DownloadFile(const Aws::String& fileName, const Aws::String& bucketName, const Aws::String& keyName);
77 
78  // User requested download cancels should go through here
79  void CancelDownload(std::shared_ptr<DownloadFileRequest>& fileRequest) const;
80 
81  const std::shared_ptr<Aws::S3::S3Client>& GetS3Client() { return m_s3Client; }
82 
83  uint32_t GetConfigBufferCount() const { return m_config.m_uploadBufferCount; }
84 
85  friend class UploadFileRequest;
86  friend class DownloadFileRequest;
87  private:
88 
89  void UploadFileInternal(std::shared_ptr<UploadFileRequest>& fileRequest);
90 
91  void ProcessSingleBuffer(std::shared_ptr<UploadFileRequest>& request, const std::shared_ptr<UploadBuffer>& buffer);
92 
93  void CancelUploadInternal(std::shared_ptr<UploadFileRequest>& fileRequest) const;
94 
95  void BeginDownloadFile(std::shared_ptr<DownloadFileRequest>& fileRequest) const;
96  void DownloadFileInternal(std::shared_ptr<DownloadFileRequest>& fileRequest) const;
97 
98  void GetContentsInternal(std::shared_ptr<DownloadFileRequest>& request) const;
99 
100  void CancelDownloadInternal(std::shared_ptr<DownloadFileRequest>& fileRequest) const;
101 
102  static void OnCreateBucket(const Aws::S3::S3Client* s3Client,
105  const std::shared_ptr<const Aws::Client::AsyncCallerContext>& context);
106 
107  static void OnCreateMultipartUpload(const Aws::S3::S3Client* s3Client,
110  const std::shared_ptr<const Aws::Client::AsyncCallerContext>& context);
111 
112  static void OnHeadBucket(const Aws::S3::S3Client* s3Client,
113  const Aws::S3::Model::HeadBucketRequest& request,
114  const Aws::S3::Model::HeadBucketOutcome& outcome,
115  const std::shared_ptr<const Aws::Client::AsyncCallerContext>& context);
116 
117  static void OnUploadPartRequest(const Aws::S3::S3Client* s3Client,
118  const Aws::S3::Model::UploadPartRequest& request,
119  const Aws::S3::Model::UploadPartOutcome& outcome,
120  const std::shared_ptr<const Aws::Client::AsyncCallerContext>& context);
121 
122  static void OnCompleteMultipartUpload(const Aws::S3::S3Client* s3Client,
125  const std::shared_ptr<const Aws::Client::AsyncCallerContext>& context);
126 
127  static void OnPutObject(const Aws::S3::S3Client* s3Client,
128  const Aws::S3::Model::PutObjectRequest& request,
129  const Aws::S3::Model::PutObjectOutcome& outcome,
130  const std::shared_ptr<const Aws::Client::AsyncCallerContext>& context);
131 
132  static void OnDownloadGetObject(const Aws::S3::S3Client* s3Client,
133  const Aws::S3::Model::GetObjectRequest& request,
134  const Aws::S3::Model::GetObjectOutcome& outcome,
135  const std::shared_ptr<const Aws::Client::AsyncCallerContext>& context);
136 
137  static void OnDownloadListObjects(const Aws::S3::S3Client* s3Client,
138  const Aws::S3::Model::ListObjectsRequest& request,
139  const Aws::S3::Model::ListObjectsOutcome& outcome,
140  const std::shared_ptr<const Aws::Client::AsyncCallerContext>& context);
141 
142  static void OnUploadGetObject(const Aws::S3::S3Client* s3Client,
143  const Aws::S3::Model::GetObjectRequest& request,
144  const Aws::S3::Model::GetObjectOutcome& outcome,
145  const std::shared_ptr<const Aws::Client::AsyncCallerContext>& context);
146 
147  static void OnHeadObject(const Aws::S3::S3Client* s3Client,
148  const Aws::S3::Model::HeadObjectRequest& request,
149  const Aws::S3::Model::HeadObjectOutcome& outcome,
150  const std::shared_ptr<const Aws::Client::AsyncCallerContext>& context);
151 
152  static void OnUploadListObjects(const Aws::S3::S3Client* s3Client,
153  const Aws::S3::Model::ListObjectsRequest& request,
154  const Aws::S3::Model::ListObjectsOutcome& outcome,
155  const std::shared_ptr<const Aws::Client::AsyncCallerContext>& context);
156 
157  static void OnAbortMultipart(const Aws::S3::S3Client* ,
160  const std::shared_ptr<const Aws::Client::AsyncCallerContext>& ) {}
161 
162  std::shared_ptr< UploadBufferScopedResourceSetType > AcquireUploadBuffers(uint32_t bufferCount);
163 
164  std::shared_ptr<Aws::S3::S3Client> m_s3Client;
166 
167  std::shared_ptr<UploadBufferResourceManagerType> m_uploadBufferManager;
168 
169 };
170 
171 } // namespace Transfer
172 } // namespace Aws
173 
174 #endif
std::map< K, V, std::less< K >, Aws::Allocator< std::pair< const K, V > > > Map
Definition: AWSMap.h:28
const uint64_t MB5_BUFFER_SIZE
#define AWS_TRANSFER_API
std::basic_string< char, std::char_traits< char >, Aws::Allocator< char > > String
Definition: AWSString.h:97
uint32_t GetConfigBufferCount() const
const std::shared_ptr< Aws::S3::S3Client > & GetS3Client()
std::shared_ptr< UploadBufferResourceManagerType > m_uploadBufferManager
JSON (JavaScript Object Notation).