AWSS3TransferManager.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. //
  2. // Copyright 2010-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License").
  5. // You may not use this file except in compliance with the License.
  6. // A copy of the License is located at
  7. //
  8. // http://aws.amazon.com/apache2.0
  9. //
  10. // or in the "license" file accompanying this file. This file is distributed
  11. // on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
  12. // express or implied. See the License for the specific language governing
  13. // permissions and limitations under the License.
  14. //
  15. #import "AWSS3Service.h"
  16. NS_ASSUME_NONNULL_BEGIN
  17. FOUNDATION_EXPORT NSString *const AWSS3TransferManagerErrorDomain;
  18. typedef NS_ENUM(NSInteger, AWSS3TransferManagerErrorType) {
  19. AWSS3TransferManagerErrorUnknown,
  20. AWSS3TransferManagerErrorCancelled,
  21. AWSS3TransferManagerErrorPaused,
  22. AWSS3TransferManagerErrorCompleted,
  23. AWSS3TransferManagerErrorInternalInConsistency,
  24. AWSS3TransferManagerErrorMissingRequiredParameters,
  25. AWSS3TransferManagerErrorInvalidParameters,
  26. };
  27. typedef NS_ENUM(NSInteger, AWSS3TransferManagerRequestState) {
  28. AWSS3TransferManagerRequestStateNotStarted,
  29. AWSS3TransferManagerRequestStateRunning,
  30. AWSS3TransferManagerRequestStatePaused,
  31. AWSS3TransferManagerRequestStateCanceling,
  32. AWSS3TransferManagerRequestStateCompleted,
  33. };
  34. typedef void (^AWSS3TransferManagerResumeAllBlock) (AWSRequest *request);
  35. @class AWSS3;
  36. @class AWSS3TransferManagerUploadRequest;
  37. @class AWSS3TransferManagerUploadOutput;
  38. @class AWSS3TransferManagerDownloadRequest;
  39. @class AWSS3TransferManagerDownloadOutput;
  40. /**
  41. High level utility for managing transfers to Amazon S3. S3TransferManager provides a simple API for uploading and downloading content to Amazon S3, and makes extensive use of Amazon S3 multipart uploads to achieve enhanced throughput, performance and reliability.
  42. @warning The `AWSS3TransferManager` is deprecated. Please use `AWSS3TransferUtility` for Amazon S3 upload and download operations.
  43. @deprecated Please use `AWSS3TransferUtility` for upload and download operations.
  44. */
  45. DEPRECATED_MSG_ATTRIBUTE("Use `AWSS3TransferUtility` for upload and download operations.")
  46. @interface AWSS3TransferManager : AWSService
  47. /**
  48. Returns the singleton service client. If the singleton object does not exist, the SDK instantiates the default service client with `defaultServiceConfiguration` from `[AWSServiceManager defaultServiceManager]`. The reference to this object is maintained by the SDK, and you do not need to retain it manually.
  49. For example, set the default service configuration in `- application:didFinishLaunchingWithOptions:`
  50. *Swift*
  51. func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
  52. let credentialProvider = AWSCognitoCredentialsProvider(regionType: .USEast1, identityPoolId: "YourIdentityPoolId")
  53. let configuration = AWSServiceConfiguration(region: .USEast1, credentialsProvider: credentialProvider)
  54. AWSServiceManager.defaultServiceManager().defaultServiceConfiguration = configuration
  55. return true
  56. }
  57. *Objective-C*
  58. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  59. AWSCognitoCredentialsProvider *credentialsProvider = [[AWSCognitoCredentialsProvider alloc] initWithRegionType:AWSRegionUSEast1
  60. identityPoolId:@"YourIdentityPoolId"];
  61. AWSServiceConfiguration *configuration = [[AWSServiceConfiguration alloc] initWithRegion:AWSRegionUSEast1
  62. credentialsProvider:credentialsProvider];
  63. [AWSServiceManager defaultServiceManager].defaultServiceConfiguration = configuration;
  64. return YES;
  65. }
  66. Then call the following to get the default service client:
  67. *Swift*
  68. let S3TransferManager = AWSS3TransferManager.defaultS3TransferManager()
  69. *Objective-C*
  70. AWSS3TransferManager *S3TransferManager = [AWSS3TransferManager defaultS3TransferManager];
  71. @return The default service client.
  72. */
  73. + (instancetype)defaultS3TransferManager;
  74. /**
  75. Creates a service client with the given service configuration and registers it for the key.
  76. For example, set the default service configuration in `- application:didFinishLaunchingWithOptions:`
  77. *Swift*
  78. func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
  79. let credentialProvider = AWSCognitoCredentialsProvider(regionType: .USEast1, identityPoolId: "YourIdentityPoolId")
  80. let configuration = AWSServiceConfiguration(region: .USWest2, credentialsProvider: credentialProvider)
  81. AWSS3TransferManager.registerS3TransferManagerWithConfiguration(configuration, forKey: "USWest2S3TransferManager")
  82. return true
  83. }
  84. *Objective-C*
  85. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  86. AWSCognitoCredentialsProvider *credentialsProvider = [[AWSCognitoCredentialsProvider alloc] initWithRegionType:AWSRegionUSEast1
  87. identityPoolId:@"YourIdentityPoolId"];
  88. AWSServiceConfiguration *configuration = [[AWSServiceConfiguration alloc] initWithRegion:AWSRegionUSWest2
  89. credentialsProvider:credentialsProvider];
  90. [AWSS3TransferManager registerS3TransferManagerWithConfiguration:configuration forKey:@"USWest2S3TransferManager"];
  91. return YES;
  92. }
  93. Then call the following to get the service client:
  94. *Swift*
  95. let S3TransferManager = AWSS3TransferManager(forKey: "USWest2S3TransferManager")
  96. *Objective-C*
  97. AWSS3TransferManager *S3TransferManager = [AWSS3TransferManager S3TransferManagerForKey:@"USWest2S3TransferManager"];
  98. @warning After calling this method, do not modify the configuration object. It may cause unspecified behaviors.
  99. @param configuration A service configuration object.
  100. @param key A string to identify the service client.
  101. */
  102. + (void)registerS3TransferManagerWithConfiguration:(AWSServiceConfiguration *)configuration forKey:(NSString *)key;
  103. /**
  104. Retrieves the service client associated with the key. You need to call `+ registerS3TransferManagerWithConfiguration:forKey:` before invoking this method.
  105. For example, set the default service configuration in `- application:didFinishLaunchingWithOptions:`
  106. *Swift*
  107. func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
  108. let credentialProvider = AWSCognitoCredentialsProvider(regionType: .USEast1, identityPoolId: "YourIdentityPoolId")
  109. let configuration = AWSServiceConfiguration(region: .USWest2, credentialsProvider: credentialProvider)
  110. AWSS3TransferManager.registerS3TransferManagerWithConfiguration(configuration, forKey: "USWest2S3TransferManager")
  111. return true
  112. }
  113. *Objective-C*
  114. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  115. AWSCognitoCredentialsProvider *credentialsProvider = [[AWSCognitoCredentialsProvider alloc] initWithRegionType:AWSRegionUSEast1
  116. identityPoolId:@"YourIdentityPoolId"];
  117. AWSServiceConfiguration *configuration = [[AWSServiceConfiguration alloc] initWithRegion:AWSRegionUSWest2
  118. credentialsProvider:credentialsProvider];
  119. [AWSS3TransferManager registerS3TransferManagerWithConfiguration:configuration forKey:@"USWest2S3TransferManager"];
  120. return YES;
  121. }
  122. Then call the following to get the service client:
  123. *Swift*
  124. let S3TransferManager = AWSS3TransferManager(forKey: "USWest2S3TransferManager")
  125. *Objective-C*
  126. AWSS3TransferManager *S3TransferManager = [AWSS3TransferManager S3TransferManagerForKey:@"USWest2S3TransferManager"];
  127. @param key A string to identify the service client.
  128. @return An instance of the service client.
  129. */
  130. + (instancetype)S3TransferManagerForKey:(NSString *)key;
  131. /**
  132. Removes the service client associated with the key and release it.
  133. @warning Before calling this method, make sure no method is running on this client.
  134. @param key A string to identify the service client.
  135. */
  136. + (void)removeS3TransferManagerForKey:(NSString *)key;
  137. /**
  138. Schedules a new transfer to upload data to Amazon S3.
  139. @param uploadRequest The upload request.
  140. @return AWSTask.
  141. */
  142. - (AWSTask *)upload:(AWSS3TransferManagerUploadRequest *)uploadRequest;
  143. /**
  144. Schedules a new transfer to download data from Amazon S3 and save it to the specified file.
  145. @param downloadRequest The download request.
  146. @return AWSTask.
  147. */
  148. - (AWSTask *)download:(AWSS3TransferManagerDownloadRequest *)downloadRequest;
  149. /**
  150. Cancels all of the upload and download requests.
  151. @return AWSTask.
  152. */
  153. - (AWSTask *)cancelAll;
  154. /**
  155. Pauses all of the upload and download requests.
  156. @return AWSTask.
  157. */
  158. - (AWSTask *)pauseAll;
  159. /**
  160. Resumes all of the upload and download requests.
  161. @param block The block to optionally re-set the progress blocks to the requests.
  162. @return AWSTask.
  163. */
  164. - (AWSTask *)resumeAll:(AWSS3TransferManagerResumeAllBlock)block;
  165. /**
  166. Clears the local cache.
  167. @return AWSTask.
  168. */
  169. - (AWSTask *)clearCache;
  170. @end
  171. DEPRECATED_MSG_ATTRIBUTE("Use `AWSS3TransferUtility` for upload and download operations.")
  172. @interface AWSS3TransferManagerUploadRequest : AWSS3PutObjectRequest
  173. @property (nonatomic, assign, readonly) AWSS3TransferManagerRequestState state;
  174. @property (nonatomic, strong) NSURL *body;
  175. @end
  176. DEPRECATED_MSG_ATTRIBUTE("Use `AWSS3TransferUtility` for upload and download operations.")
  177. @interface AWSS3TransferManagerUploadOutput : AWSS3PutObjectOutput
  178. @end
  179. DEPRECATED_MSG_ATTRIBUTE("Use `AWSS3TransferUtility` for upload and download operations.")
  180. @interface AWSS3TransferManagerDownloadRequest : AWSS3GetObjectRequest
  181. @property (nonatomic, assign, readonly) AWSS3TransferManagerRequestState state;
  182. @end
  183. DEPRECATED_MSG_ATTRIBUTE("Use `AWSS3TransferUtility` for upload and download operations.")
  184. @interface AWSS3TransferManagerDownloadOutput : AWSS3GetObjectOutput
  185. @end
  186. NS_ASSUME_NONNULL_END