aliyun-oss-react-native

OSSClient.h 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. //
  2. // OSSClient.h
  3. // oss_ios_sdk
  4. //
  5. // Created by zhouzhuo on 8/16/15.
  6. // Copyright (c) 2015 aliyun.com. All rights reserved.
  7. //
  8. #import <Foundation/Foundation.h>
  9. @class OSSGetServiceRequest;
  10. @class OSSCreateBucketRequest;
  11. @class OSSDeleteBucketRequest;
  12. @class OSSHeadObjectRequest;
  13. @class OSSGetBucketRequest;
  14. @class OSSGetBucketACLRequest;
  15. @class OSSGetObjectRequest;
  16. @class OSSGetObjectACLRequest;
  17. @class OSSPutObjectRequest;
  18. @class OSSPutObjectACLRequest;
  19. @class OSSDeleteObjectRequest;
  20. @class OSSDeleteMultipleObjectsRequest;
  21. @class OSSCopyObjectRequest;
  22. @class OSSInitMultipartUploadRequest;
  23. @class OSSUploadPartRequest;
  24. @class OSSCompleteMultipartUploadRequest;
  25. @class OSSListPartsRequest;
  26. @class OSSListMultipartUploadsRequest;
  27. @class OSSAbortMultipartUploadRequest;
  28. @class OSSAppendObjectRequest;
  29. @class OSSResumableUploadRequest;
  30. @class OSSMultipartUploadRequest;
  31. @class OSSTask;
  32. @class OSSExecutor;
  33. @class OSSCallBackRequest;
  34. @class OSSImagePersistRequest;
  35. @class OSSNetworking;
  36. @class OSSClientConfiguration;
  37. @protocol OSSCredentialProvider;
  38. NS_ASSUME_NONNULL_BEGIN
  39. /**
  40. OSSClient is the entry class to access OSS in an iOS client. It provides all the methods to communicate with OSS.
  41. Generally speaking, only one instance of OSSClient is needed in the whole app.
  42. */
  43. @interface OSSClient : NSObject
  44. /**
  45. OSS endpoint. It varies in different regions. Please check out OSS official website for the exact endpoints for your data.
  46. */
  47. @property (nonatomic, strong) NSString * endpoint;
  48. /**
  49. The networking instance for sending and receiving data
  50. */
  51. @property (nonatomic, strong) OSSNetworking * networking;
  52. /**
  53. The credential provider instance
  54. */
  55. @property (nonatomic, strong) id<OSSCredentialProvider> credentialProvider;
  56. /**
  57. Client configuration instance
  58. */
  59. @property (nonatomic, strong) OSSClientConfiguration * clientConfiguration;
  60. /**
  61. oss operation task queue
  62. */
  63. @property (nonatomic, strong, readonly) OSSExecutor * ossOperationExecutor;
  64. /**
  65. Initializes an OSSClient instance with the default client configuration.
  66. @endpoint it specifies domain of the bucket's region. Starting 2017, the domain must be prefixed with "https://" to follow Apple's ATS policy.
  67. For example: "https://oss-cn-hangzhou.aliyuncs.com"
  68. @credentialProvider The credential provider
  69. */
  70. - (instancetype)initWithEndpoint:(NSString *)endpoint
  71. credentialProvider:(id<OSSCredentialProvider>) credentialProvider;
  72. /**
  73. Initializes an OSSClient with the custom client configuration.
  74. @endpoint it specifies domain of the bucket's region. Starting 2017, the domain must be prefixed with "https://" to follow Apple's ATS policy.
  75. For example: "https://oss-cn-hangzhou.aliyuncs.com"
  76. @credentialProvider The credential provider
  77. @conf The custom client configuration such as retry time, timeout values, etc.
  78. */
  79. - (instancetype)initWithEndpoint:(NSString *)endpoint
  80. credentialProvider:(id<OSSCredentialProvider>)credentialProvider
  81. clientConfiguration:(OSSClientConfiguration *)conf;
  82. #pragma mark restful-api
  83. /**
  84. The corresponding RESTFul API: GetService
  85. Gets all the buckets of the current user
  86. Notes:
  87. 1. STS is not supported yet in this call.
  88. 2. When all buckets are returned, the xml in response body does not have nodes of Prefix, Marker, MaxKeys, IsTruncated and NextMarker.
  89. If there're remaining buckets to return, the xml will have these nodes. The nextMarker is the value of marker in the next call.
  90. */
  91. - (OSSTask *)getService:(OSSGetServiceRequest *)request;
  92. /**
  93. The corresponding RESTFul API: PutBucket
  94. Creates a bucket--it does not support anonymous access. By default, the datacenter used is oss-cn-hangzhou.
  95. Callers could explicitly specify the datacenter for the bucket to optimize the performance and cost or meet the regulation requirement.
  96. Notes:
  97. 1. STS is not supported yet.
  98. */
  99. - (OSSTask *)createBucket:(OSSCreateBucketRequest *)request;
  100. /**
  101. The corresponding RESTFul API: DeleteBucket
  102. Deletes a bucket.
  103. */
  104. - (OSSTask *)deleteBucket:(OSSDeleteBucketRequest *)request;
  105. /**
  106. The corresponding RESTFul API: GetBucket
  107. Lists all objects in a bucket. It could be specified with filters such as prefix, marker, delimeter and max-keys.
  108. */
  109. - (OSSTask *)getBucket:(OSSGetBucketRequest *)request;
  110. /**
  111. The corresponding RESTFul API: GetBucketACL
  112. Gets the bucket ACL.
  113. */
  114. - (OSSTask *)getBucketACL:(OSSGetBucketACLRequest *)request;
  115. /**
  116. The corresponding RESTFul API: HeadObject
  117. Gets the object's metadata information. The object's content is not returned.
  118. */
  119. - (OSSTask *)headObject:(OSSHeadObjectRequest *)request;
  120. /**
  121. The corresponding RESTFul API: GetObject
  122. Gets the whole object (includes content). It requires caller have read permission on the object.
  123. */
  124. - (OSSTask *)getObject:(OSSGetObjectRequest *)request;
  125. /**
  126. * Gets the Access Control List (ACL) of the OSS object.
  127. *
  128. * @param bucketName
  129. * Bucket name.
  130. * @param key
  131. * Object Key.
  132. * @return The OSSTask with result of objectAcls instance of the object.
  133. */
  134. - (OSSTask *)getObjectACL:(OSSGetObjectACLRequest *)request;
  135. /**
  136. The corresponding RESTFul API: PutObject
  137. Uploads a file.
  138. */
  139. - (OSSTask *)putObject:(OSSPutObjectRequest *)request;
  140. /**
  141. Sets the object's ACL. Right now an object has three access permissions: private, public-ready, public-read-write.
  142. The operation specifies the x-oss-object-acl header in the put request. The caller must be the owner of the object.
  143. If succeeds, it returns HTTP status 200; otherwise it returns related error code and error messages.
  144. */
  145. - (OSSTask *)putObjectACL:(OSSPutObjectACLRequest *)request;
  146. /**
  147. The corresponding RESTFul API: AppendObject
  148. Appends data to an existing or non-existing object. The object created by this operation is appendable.
  149. As a comparison, the object created by Put Object is normal (non-appendable).
  150. */
  151. - (OSSTask *)appendObject:(OSSAppendObjectRequest *)request;
  152. /**
  153. @brief : Appends data to an existing or non-existing object on the OSS server. The object created by this operation is appendable.
  154. request : request
  155. crc64ecma : 如果服务器上面已经存在对象,需要客户端先调用headObject获取到对象的crc64ecma,然后再调用
  156. 该接口上传数据
  157. */
  158. - (OSSTask *)appendObject:(OSSAppendObjectRequest *)request withCrc64ecma:(nullable NSString *)crc64ecma;
  159. /**
  160. The corresponding RESTFul API: copyObject
  161. Copies an existing object to another one.The operation sends a PUT request with x-oss-copy-source header to specify the source object.
  162. OSS server side will detect and copy the object. If it succeeds, the new object's metadata information will be returned.
  163. The operation applies for files less than 1GB. For big files, use UploadPartCopy RESTFul API.
  164. */
  165. - (OSSTask *)copyObject:(OSSCopyObjectRequest *)request;
  166. /**
  167. * Batch deletes the specified files under a specific bucket. If the files
  168. * are non-exist, the operation will still return successful.
  169. *
  170. * @param deleteObjectsRequest
  171. * A OSSDeleteMultipleObjectsRequest instance which specifies the
  172. * bucket and file keys to delete.
  173. * @return A OSSTask with result of OSSDeleteMultipleObjectsResult instance which specifies each
  174. * file's result in normal mode or only failed deletions in quite
  175. * mode. By default it's quite mode.
  176. */
  177. - (OSSTask *)deleteMultipleObjects:(OSSDeleteMultipleObjectsRequest *)request;
  178. /**
  179. The corresponding RESTFul API: DeleteObject
  180. Deletes an object
  181. */
  182. - (OSSTask *)deleteObject:(OSSDeleteObjectRequest *)request;
  183. /**
  184. The corresponding RESTFul API: InitiateMultipartUpload
  185. Initiates a multipart upload to get a upload Id. It's needed before starting uploading parts data.
  186. The upload Id is used for subsequential operations such as aborting the upload, querying the uploaded parts, etc.
  187. */
  188. - (OSSTask *)multipartUploadInit:(OSSInitMultipartUploadRequest *)request;
  189. /**
  190. The corresponding RESTFul API: UploadPart
  191. After the multipart upload is initiated, this API could be called to upload the data to the target file with the upload Id.
  192. Every uploaded part has a unique id called part number, which ranges from 1 to 10,000.
  193. For a given upload Id, the part number identifies the specific range of the data in the whole file.
  194. If the same part number is used for another upload, the existing data will be overwritten by the new upload.
  195. Except the last part, all other part's minimal size is 100KB.
  196. But no minimal size requirement on the last part.
  197. */
  198. - (OSSTask *)uploadPart:(OSSUploadPartRequest *)request;
  199. /**
  200. The corresponding RESTFul API: CompleteMultipartUpload
  201. This API is to complete the multipart upload after all parts data have been uploaded.
  202. It must be provided with a valid part list (each part has the part number and ETag).
  203. OSS will validate every part and then complete the multipart upload.
  204. If any part is invalid (e.g. the part is updated by another part upload), this API will fail.
  205. */
  206. - (OSSTask *)completeMultipartUpload:(OSSCompleteMultipartUploadRequest *)request;
  207. /**
  208. The corresponding RESTFul API: ListParts
  209. Lists all uploaded parts of the specified upload id.
  210. */
  211. - (OSSTask *)listParts:(OSSListPartsRequest *)request;
  212. /**
  213. The corresponding RESTFul API: ListMultipartUploads
  214. Lists all multipart uploads with the specified bucket.
  215. */
  216. - (OSSTask *)listMultipartUploads:(OSSListMultipartUploadsRequest *)request;
  217. /**
  218. The corresponding RESTFul API: AbortMultipartUpload
  219. Aborts the multipart upload by the specified upload Id.
  220. Once the multipart upload is aborted by this API, all parts data will be deleted and the upload Id is invalid anymore.
  221. */
  222. - (OSSTask *)abortMultipartUpload:(OSSAbortMultipartUploadRequest *)request;
  223. - (OSSTask *)abortResumableMultipartUpload:(OSSResumableUploadRequest *)request;
  224. - (OSSTask *)triggerCallBack:(OSSCallBackRequest *)request;
  225. #pragma mark extention method
  226. /**
  227. Generates a signed URL for the object and anyone has this URL will get the GET permission on the object.
  228. @bucketName object's bucket name
  229. @objectKey Object name
  230. @interval Expiration time in seconds. The URL could be specified with the expiration time to limit the access window on the object.
  231. */
  232. - (OSSTask *)presignConstrainURLWithBucketName:(NSString *)bucketName
  233. withObjectKey:(NSString *)objectKey
  234. withExpirationInterval:(NSTimeInterval)interval;
  235. /**
  236. Generates a signed URL for the object and anyone has this URL will get the specified permission on the object.
  237. @bucketName object's bucket name
  238. @objectKey Object name
  239. @interval Expiration time in seconds. The URL could be specified with the expiration time to limit the access window on the object.
  240. @parameter it could specify allowed HTTP methods
  241. */
  242. - (OSSTask *)presignConstrainURLWithBucketName:(NSString *)bucketName
  243. withObjectKey:(NSString *)objectKey
  244. withExpirationInterval:(NSTimeInterval)interval
  245. withParameters:(NSDictionary *)parameters;
  246. /** TODOTODO
  247. If the object's ACL is public read or public read-write, use this API to generate a signed url for sharing.
  248. @bucketName Object's bucket name
  249. @objectKey Object name
  250. */
  251. - (OSSTask *)presignPublicURLWithBucketName:(NSString *)bucketName
  252. withObjectKey:(NSString *)objectKey;
  253. /** TODOTODO
  254. If the object's ACL is public read or public read-write, use this API to generate a signed url for sharing.
  255. @bucketName Object's bucket name
  256. @objectKey Object name
  257. @parameter the request parameters.
  258. */
  259. - (OSSTask *)presignPublicURLWithBucketName:(NSString *)bucketName
  260. withObjectKey:(NSString *)objectKey
  261. withParameters:(NSDictionary *)parameters;
  262. /**
  263. TODOTODO
  264. Multipart upload API
  265. */
  266. - (OSSTask *)multipartUpload:(OSSMultipartUploadRequest *)request;
  267. /**
  268. TODOTODO
  269. Resumable upload API
  270. This API wraps the multipart upload and also enables resuming upload by reading/writing the checkpoint data.
  271. For a new file, multipartUploadInit() needs to be called first to get the upload Id. Then use this upload id to call this API to upload the data.
  272. If the upload fails, checks the error messages:
  273. If it's a recoverable error, then call this API again with the same upload Id to retry. The uploaded data will not be uploaded again.
  274. Otherwise then you may need to recreates a new upload Id and call this method again.
  275. Check out demo for the detail.
  276. */
  277. - (OSSTask *)resumableUpload:(OSSResumableUploadRequest *)request;
  278. /**
  279. Checks if the object exists
  280. @bucketName Object's bucket name
  281. @objectKey Object name
  282. return YES Object exists
  283. return NO && *error = nil Object does not exist
  284. return NO && *error != nil Error occured.
  285. */
  286. - (BOOL)doesObjectExistInBucket:(NSString *)bucketName
  287. objectKey:(NSString *)objectKey
  288. error:(const NSError **)error;
  289. /**
  290. * multipart upload sequentially in order,support resume upload
  291. */
  292. - (OSSTask *)sequentialMultipartUpload:(OSSResumableUploadRequest *)request;
  293. /*
  294. * image persist action
  295. * https://help.aliyun.com/document_detail/55811.html
  296. */
  297. - (OSSTask *)imageActionPersist:(OSSImagePersistRequest *)request;
  298. @end
  299. NS_ASSUME_NONNULL_END