OSSClient.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446
  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 OSSCallBackRequest;
  32. @class OSSImagePersistRequest;
  33. @class OSSGetBucketInfoRequest;
  34. @class OSSPutSymlinkRequest;
  35. @class OSSGetSymlinkRequest;
  36. @class OSSRestoreObjectRequest;
  37. @class OSSTask;
  38. @class OSSExecutor;
  39. @class OSSNetworking;
  40. @class OSSClientConfiguration;
  41. @protocol OSSCredentialProvider;
  42. NS_ASSUME_NONNULL_BEGIN
  43. /**
  44. OSSClient is the entry class to access OSS in an iOS client. It provides all the methods to communicate with OSS.
  45. Generally speaking, only one instance of OSSClient is needed in the whole app.
  46. */
  47. @interface OSSClient : NSObject
  48. /**
  49. OSS endpoint. It varies in different regions. Please check out OSS official website for the exact endpoints for your data.
  50. */
  51. @property (nonatomic, strong) NSString * endpoint;
  52. /**
  53. The networking instance for sending and receiving data
  54. */
  55. @property (nonatomic, strong) OSSNetworking * networking;
  56. /**
  57. The credential provider instance
  58. */
  59. @property (nonatomic, strong) id<OSSCredentialProvider> credentialProvider;
  60. /**
  61. Client configuration instance
  62. */
  63. @property (nonatomic, strong) OSSClientConfiguration * clientConfiguration;
  64. /**
  65. oss operation task queue
  66. */
  67. @property (nonatomic, strong, readonly) OSSExecutor * ossOperationExecutor;
  68. /**
  69. Initializes an OSSClient instance with the default client configuration.
  70. @endpoint it specifies domain of the bucket's region. Starting 2017, the domain must be prefixed with "https://" to follow Apple's ATS policy.
  71. For example: "https://oss-cn-hangzhou.aliyuncs.com"
  72. @credentialProvider The credential provider
  73. */
  74. - (instancetype)initWithEndpoint:(NSString *)endpoint
  75. credentialProvider:(id<OSSCredentialProvider>) credentialProvider;
  76. /**
  77. Initializes an OSSClient with the custom client configuration.
  78. @endpoint it specifies domain of the bucket's region. Starting 2017, the domain must be prefixed with "https://" to follow Apple's ATS policy.
  79. For example: "https://oss-cn-hangzhou.aliyuncs.com"
  80. @credentialProvider The credential provider
  81. @conf The custom client configuration such as retry time, timeout values, etc.
  82. */
  83. - (instancetype)initWithEndpoint:(NSString *)endpoint
  84. credentialProvider:(id<OSSCredentialProvider>)credentialProvider
  85. clientConfiguration:(OSSClientConfiguration *)conf;
  86. #pragma mark restful-api
  87. /**
  88. The corresponding RESTFul API: GetService
  89. Gets all the buckets of the current user
  90. Notes:
  91. 1. STS is not supported yet in this call.
  92. 2. When all buckets are returned, the xml in response body does not have nodes of Prefix, Marker, MaxKeys, IsTruncated and NextMarker.
  93. If there're remaining buckets to return, the xml will have these nodes. The nextMarker is the value of marker in the next call.
  94. */
  95. - (OSSTask *)getService:(OSSGetServiceRequest *)request;
  96. @end
  97. @interface OSSClient (Bucket)
  98. /**
  99. The corresponding RESTFul API: PutBucket
  100. Creates a bucket--it does not support anonymous access. By default, the datacenter used is oss-cn-hangzhou.
  101. Callers could explicitly specify the datacenter for the bucket to optimize the performance and cost or meet the regulation requirement.
  102. Notes:
  103. 1. STS is not supported yet.
  104. */
  105. - (OSSTask *)createBucket:(OSSCreateBucketRequest *)request;
  106. /**
  107. The corresponding RESTFul API: DeleteBucket
  108. Deletes a bucket.
  109. */
  110. - (OSSTask *)deleteBucket:(OSSDeleteBucketRequest *)request;
  111. /**
  112. The corresponding RESTFul API: GetBucket
  113. Lists all objects in a bucket. It could be specified with filters such as prefix, marker, delimeter and max-keys.
  114. */
  115. - (OSSTask *)getBucket:(OSSGetBucketRequest *)request;
  116. /**
  117. The corresponding RESTFul API: GetBucketInfo
  118. Gets the {@link Bucket}'s basic information as well as its ACL.
  119. */
  120. - (OSSTask *)getBucketInfo:(OSSGetBucketInfoRequest *)request;
  121. /**
  122. The corresponding RESTFul API: GetBucketACL
  123. Gets the bucket ACL.
  124. */
  125. - (OSSTask *)getBucketACL:(OSSGetBucketACLRequest *)request;
  126. @end
  127. @interface OSSClient (Object)
  128. /**
  129. The corresponding RESTFul API: HeadObject
  130. Gets the object's metadata information. The object's content is not returned.
  131. */
  132. - (OSSTask *)headObject:(OSSHeadObjectRequest *)request;
  133. /**
  134. The corresponding RESTFul API: GetObject
  135. Gets the whole object (includes content). It requires caller have read permission on the object.
  136. */
  137. - (OSSTask *)getObject:(OSSGetObjectRequest *)request;
  138. /**
  139. The corresponding RESTFul API: GetObjectACL
  140. get the acl of an object.
  141. */
  142. - (OSSTask *)getObjectACL:(OSSGetObjectACLRequest *)request;
  143. /**
  144. The corresponding RESTFul API: PutObject
  145. Uploads a file.
  146. */
  147. - (OSSTask *)putObject:(OSSPutObjectRequest *)request;
  148. /**
  149. Sets the object's ACL. Right now an object has three access permissions: private, public-ready, public-read-write.
  150. The operation specifies the x-oss-object-acl header in the put request. The caller must be the owner of the object.
  151. If succeeds, it returns HTTP status 200; otherwise it returns related error code and error messages.
  152. */
  153. - (OSSTask *)putObjectACL:(OSSPutObjectACLRequest *)request;
  154. /**
  155. The corresponding RESTFul API: AppendObject
  156. Appends data to an existing or non-existing object. The object created by this operation is appendable.
  157. As a comparison, the object created by Put Object is normal (non-appendable).
  158. */
  159. - (OSSTask *)appendObject:(OSSAppendObjectRequest *)request;
  160. /**
  161. * @brief Appends data to an existing or non-existing object on the OSS server.
  162. * The object created by this operation is appendable.
  163. * @request request
  164. * @crc64ecma crc64ecma
  165. * if object has been stored on OSS server, you need to invoke headObject
  166. * api get object's crc64ecma,then use this api to append data to the
  167. * object.
  168. */
  169. - (OSSTask *)appendObject:(OSSAppendObjectRequest *)request withCrc64ecma:(nullable NSString *)crc64ecma;
  170. /**
  171. The corresponding RESTFul API: copyObject
  172. Copies an existing object to another one.The operation sends a PUT request with x-oss-copy-source header to specify the source object.
  173. OSS server side will detect and copy the object. If it succeeds, the new object's metadata information will be returned.
  174. The operation applies for files less than 1GB. For big files, use UploadPartCopy RESTFul API.
  175. */
  176. - (OSSTask *)copyObject:(OSSCopyObjectRequest *)request;
  177. /**
  178. * Batch deletes the specified files under a specific bucket. If the files
  179. * are non-exist, the operation will still return successful.
  180. *
  181. * @param request
  182. * A OSSDeleteMultipleObjectsRequest instance which specifies the
  183. * bucket and file keys to delete.
  184. * @return A OSSTask with result of OSSDeleteMultipleObjectsResult instance which specifies each
  185. * file's result in normal mode or only failed deletions in quite
  186. * mode. By default it's quite mode.
  187. */
  188. - (OSSTask *)deleteMultipleObjects:(OSSDeleteMultipleObjectsRequest *)request;
  189. /**
  190. The corresponding RESTFul API: DeleteObject
  191. Deletes an object
  192. */
  193. - (OSSTask *)deleteObject:(OSSDeleteObjectRequest *)request;
  194. /**
  195. * Creates a symbol link to a target file under the bucket---this is not
  196. * supported for archive class bucket.
  197. *
  198. * @param request
  199. * A OSSPutSymlinkRequest instance that specifies the
  200. * bucket name, symlink name.
  201. * @return An instance of OSSTask. On successful execution, `task.result` will
  202. * contain an instance of `OSSPutSymlinkResult`,otherwise will contain
  203. * an instance of NSError.
  204. *
  205. * for more information,please refer to https://help.aliyun.com/document_detail/45126.html
  206. */
  207. - (OSSTask *)putSymlink:(OSSPutSymlinkRequest *)request;
  208. /**
  209. * Gets the symlink information for the given symlink name.
  210. *
  211. * @param request
  212. * A OSSGetSymlinkRequest instance which specifies the bucket
  213. * name and symlink name.
  214. * @return An instance of OSSTask. On successful execution, `task.result` will
  215. * contain an instance of `OSSGetSymlinkResult`,otherwise will contain
  216. * an instance of NSError.
  217. *
  218. * for more information,please refer to https://help.aliyun.com/document_detail/45146.html
  219. */
  220. - (OSSTask *)getSymlink:(OSSGetSymlinkRequest *)request;
  221. /**
  222. * Restores the object of archive storage. The function is not applicable to
  223. * Normal or IA storage. The restoreObject() needs to be called prior to
  224. * calling getObject() on an archive object.
  225. *
  226. * @param request
  227. * A container for the necessary parameters to execute the RestoreObject
  228. * service method.
  229. *
  230. * @return An instance of OSSTask. On successful execution, `task.result` will
  231. * contain an instance of `OSSRestoreObjectResult`,otherwise will contain
  232. * an instance of NSError.
  233. *
  234. * for more information,please refer to https://help.aliyun.com/document_detail/52930.html
  235. */
  236. - (OSSTask *)restoreObject:(OSSRestoreObjectRequest *)request;
  237. @end
  238. @interface OSSClient (MultipartUpload)
  239. /**
  240. The corresponding RESTFul API: InitiateMultipartUpload
  241. Initiates a multipart upload to get a upload Id. It's needed before starting uploading parts data.
  242. The upload Id is used for subsequential operations such as aborting the upload, querying the uploaded parts, etc.
  243. */
  244. - (OSSTask *)multipartUploadInit:(OSSInitMultipartUploadRequest *)request;
  245. /**
  246. The corresponding RESTFul API: UploadPart
  247. After the multipart upload is initiated, this API could be called to upload the data to the target file with the upload Id.
  248. Every uploaded part has a unique id called part number, which ranges from 1 to 10,000.
  249. For a given upload Id, the part number identifies the specific range of the data in the whole file.
  250. If the same part number is used for another upload, the existing data will be overwritten by the new upload.
  251. Except the last part, all other part's minimal size is 100KB.
  252. But no minimal size requirement on the last part.
  253. */
  254. - (OSSTask *)uploadPart:(OSSUploadPartRequest *)request;
  255. /**
  256. The corresponding RESTFul API: CompleteMultipartUpload
  257. This API is to complete the multipart upload after all parts data have been uploaded.
  258. It must be provided with a valid part list (each part has the part number and ETag).
  259. OSS will validate every part and then complete the multipart upload.
  260. If any part is invalid (e.g. the part is updated by another part upload), this API will fail.
  261. */
  262. - (OSSTask *)completeMultipartUpload:(OSSCompleteMultipartUploadRequest *)request;
  263. /**
  264. The corresponding RESTFul API: ListParts
  265. Lists all uploaded parts of the specified upload id.
  266. */
  267. - (OSSTask *)listParts:(OSSListPartsRequest *)request;
  268. /**
  269. The corresponding RESTFul API: ListMultipartUploads
  270. Lists all multipart uploads with the specified bucket.
  271. */
  272. - (OSSTask *)listMultipartUploads:(OSSListMultipartUploadsRequest *)request;
  273. /**
  274. The corresponding RESTFul API: AbortMultipartUpload
  275. Aborts the multipart upload by the specified upload Id.
  276. Once the multipart upload is aborted by this API, all parts data will be deleted and the upload Id is invalid anymore.
  277. */
  278. - (OSSTask *)abortMultipartUpload:(OSSAbortMultipartUploadRequest *)request;
  279. - (OSSTask *)abortResumableMultipartUpload:(OSSResumableUploadRequest *)request;
  280. /**
  281. Multipart upload API
  282. */
  283. - (OSSTask *)multipartUpload:(OSSMultipartUploadRequest *)request;
  284. /**
  285. TODOTODO
  286. Resumable upload API
  287. This API wraps the multipart upload and also enables resuming upload by reading/writing the checkpoint data.
  288. 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.
  289. If the upload fails, checks the error messages:
  290. 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.
  291. Otherwise then you may need to recreates a new upload Id and call this method again.
  292. Check out demo for the detail.
  293. */
  294. - (OSSTask *)resumableUpload:(OSSResumableUploadRequest *)request;
  295. /**
  296. * multipart upload sequentially in order,support resume upload
  297. */
  298. - (OSSTask *)sequentialMultipartUpload:(OSSResumableUploadRequest *)request;
  299. @end
  300. @interface OSSClient (PresignURL)
  301. /**
  302. Generates a signed URL for the object and anyone has this URL will get the GET permission on the object.
  303. @bucketName object's bucket name
  304. @objectKey Object name
  305. @interval Expiration time in seconds. The URL could be specified with the expiration time to limit the access window on the object.
  306. */
  307. - (OSSTask *)presignConstrainURLWithBucketName:(NSString *)bucketName
  308. withObjectKey:(NSString *)objectKey
  309. withExpirationInterval:(NSTimeInterval)interval;
  310. /**
  311. Generates a signed URL for the object and anyone has this URL will get the specified permission on the object.
  312. @bucketName object's bucket name
  313. @objectKey Object name
  314. @interval Expiration time in seconds. The URL could be specified with the expiration time to limit the access window on the object.
  315. @parameter it could specify allowed HTTP methods
  316. */
  317. - (OSSTask *)presignConstrainURLWithBucketName:(NSString *)bucketName
  318. withObjectKey:(NSString *)objectKey
  319. withExpirationInterval:(NSTimeInterval)interval
  320. withParameters:(NSDictionary *)parameters;
  321. /**
  322. Generates a signed URL for the object and anyone has this URL will get the specified permission on the object. currently only support get and head method.
  323. @bucketName object's bucket name
  324. @objectKey Object name
  325. @httpMethod http method.currently only support get and head.
  326. @interval Expiration time in seconds. The URL could be specified with the expiration time to limit the access window on the object.
  327. @parameter it could specify allowed HTTP methods
  328. */
  329. - (OSSTask *)presignConstrainURLWithBucketName:(NSString *)bucketName
  330. withObjectKey:(NSString *)objectKey
  331. httpMethod:(NSString *)method
  332. withExpirationInterval:(NSTimeInterval)interval
  333. withParameters:(NSDictionary *)parameters;
  334. /**
  335. If the object's ACL is public read or public read-write, use this API to generate a signed url for sharing.
  336. @bucketName Object's bucket name
  337. @objectKey Object name
  338. */
  339. - (OSSTask *)presignPublicURLWithBucketName:(NSString *)bucketName
  340. withObjectKey:(NSString *)objectKey;
  341. /** TODOTODO
  342. If the object's ACL is public read or public read-write, use this API to generate a signed url for sharing.
  343. @bucketName Object's bucket name
  344. @objectKey Object name
  345. @parameter the request parameters.
  346. */
  347. - (OSSTask *)presignPublicURLWithBucketName:(NSString *)bucketName
  348. withObjectKey:(NSString *)objectKey
  349. withParameters:(NSDictionary *)parameters;
  350. @end
  351. @interface OSSClient (ImageService)
  352. /*
  353. * image persist action
  354. * https://help.aliyun.com/document_detail/55811.html
  355. */
  356. - (OSSTask *)imageActionPersist:(OSSImagePersistRequest *)request;
  357. @end
  358. @interface OSSClient (Utilities)
  359. /**
  360. Checks if the object exists
  361. @bucketName Object's bucket name
  362. @objectKey Object name
  363. return YES Object exists
  364. return NO && *error = nil Object does not exist
  365. return NO && *error != nil Error occured.
  366. */
  367. - (BOOL)doesObjectExistInBucket:(NSString *)bucketName
  368. objectKey:(NSString *)objectKey
  369. error:(const NSError **)error;
  370. @end
  371. @interface OSSClient (Callback)
  372. - (OSSTask *)triggerCallBack:(OSSCallBackRequest *)request;
  373. @end
  374. NS_ASSUME_NONNULL_END