用工小程序前端代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

4887 lines
152 KiB

6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
  1. # oss-js-sdk
  2. [![NPM version][npm-image]][npm-url]
  3. [![build status][travis-image]][travis-url]
  4. [![coverage][cov-image]][cov-url]
  5. [![David deps][david-image]][david-url]
  6. [npm-image]: https://img.shields.io/npm/v/ali-oss.svg?style=flat-square
  7. [npm-url]: https://npmjs.org/package/ali-oss
  8. [travis-image]: https://img.shields.io/travis/ali-sdk/ali-oss/master.svg?style=flat-square
  9. [travis-url]: https://travis-ci.org/ali-sdk/ali-oss.svg?branch=master
  10. [cov-image]: http://codecov.io/github/ali-sdk/ali-oss/coverage.svg?branch=master
  11. [cov-url]: http://codecov.io/github/ali-sdk/ali-oss?branch=master
  12. [david-image]: https://img.shields.io/david/ali-sdk/ali-oss.svg?style=flat-square
  13. [david-url]: https://david-dm.org/ali-sdk/ali-oss
  14. aliyun OSS(Object Storage Service) js client for Node and Browser env.
  15. `NOTE`: For SDK `5.X` document, please go to [README.md](https://github.com/ali-sdk/ali-oss/blob/5.x/README.md)
  16. ## Install
  17. ```bash
  18. npm install ali-oss --save
  19. ```
  20. ## Compatibility
  21. ### Node
  22. Node.js >= 8.0.0 required. You can use 4.x in Node.js < 8.
  23. ### Browser
  24. - IE >= 10 & Edge
  25. - Major versions of Chrome/Firefox/Safari
  26. - Major versions of Android/iOS/WP
  27. `Note`:
  28. - For Lower browsers you can refer to [PostObject](https://help.aliyun.com/document_detail/31988.html), if you want to see more practices ,please refer to [Web Post](https://help.aliyun.com/document_detail/31923.html)
  29. ### QA
  30. Please log in to the official website and contact technical support.
  31. ## License
  32. [MIT](LICENSE)
  33. # OSS Usage
  34. OSS, Object Storage Service. Equal to well known Amazon [S3](http://aws.amazon.com/s3/).
  35. All operation use es7 async/await to implement. All api is async function.
  36. ## Summary
  37. - [Node Usage](#node-usage)
  38. - [Browser Usage](#browser-usage)
  39. - [Data Regions](#data-regions)
  40. - [Create Account](#create-account)
  41. - [Create A Bucket Instance](#create-a-bucket-instance)
  42. - [oss(options)](#ossoptions)
  43. - [Bucket Operations](#bucket-operations)
  44. - Base
  45. - [.listBuckets(query[, options])](#listbucketsquery-options)
  46. - [.putBucket(name[, options])](#putbucketname-options)
  47. - [.useBucket(name)](#usebucketname)
  48. - [.deleteBucket(name[, options])](#deletebucketname-options)
  49. - [.getBucketInfo(name)](#getbucketinfoname)
  50. - [.getBucketStat(name)](#getbucketstatname)
  51. - [.getBucketLocation(name)](#getbucketlocationname)
  52. - ACL
  53. - [.putBucketACL(name, acl[, options])](#putbucketaclname-acl-options)
  54. - [.getBucketACL(name[, options])](#getbucketaclname-options)
  55. - Logging
  56. - [.putBucketLogging(name, prefix[, options])](#putbucketloggingname-prefix-options)
  57. - [.getBucketLogging(name[, options])](#getbucketloggingname-options)
  58. - [.deleteBucketLogging(name[, options])](#deletebucketloggingname-options)
  59. - Website
  60. - [.putBucketWebsite(name, config[, options])](#putbucketwebsitename-config-options)
  61. - [.getBucketWebsite(name[, options])](#getbucketwebsitename-options)
  62. - [.deleteBucketWebsite(name, region[, options])](#deletebucketwebsitename-options)
  63. - Referer
  64. - [.putBucketReferer(name, allowEmpty, referers[, options])](#putbucketreferername-allowempty-referers-options)
  65. - [.getBucketReferer(name[, options])](#getbucketreferername-options)
  66. - [.deleteBucketReferer(name[, options])](#deletebucketreferername-options)
  67. - Lifecycle
  68. - [.putBucketLifecycle(name, rules[, options])](#putbucketlifecyclename-rules-options)
  69. - [.getBucketLifecycle(name[, options])](#getbucketlifecyclename-options)
  70. - [.deleteBucketLifecycle(name[, options])](#deletebucketlifecyclename-options)
  71. - CORS
  72. - [.putBucketCORS(name, rules[, options])](#putbucketcorsname-rules-options)
  73. - [.getBucketCORS(name[, options])](#getbucketcorsname-options)
  74. - [.deleteBucketCORS(name[, options])](#deletebucketcorsname-options)
  75. - RequestPayment
  76. - [.getBucketRequestPayment(bucketName[, options])](#getbucketrequestpaymentbucketname-options)
  77. - [.putBucketRequestPayment(bucketName, payer[, options])](#putBucketRequestpaymentbucketname-payer-options)
  78. - BucketEncryption
  79. - [.putBucketEncryption(name[, rules])](#putbucketencryptionname-rules)
  80. - [.getBucketEncryption(name)](#getbucketencryptionname)
  81. - [.deleteBucketEncryption(name)](#deletebucketencryptionname)
  82. - tagging
  83. - [.putBucketTags(name, tag[, options])](#putBucketTagsname-tag-options)
  84. - [.getBucketTags(name, [, options])](#getBucketTagsname-options)
  85. - [.deleteBucketTags(name, [, options])](#deleteBucketTagsname-options)
  86. - policy
  87. - [.putBucketPolicy(name, policy[, options])](#putBucketPolicyname-policy-options)
  88. - [.getBucketPolicy(name, [, options])](#getBucketPolicyname-options)
  89. - [.deleteBucketPolicy(name, [, options])](#deleteBucketPolicyname-options)
  90. - versioning
  91. - [.getBucketVersioning(name, [, options])](#getBucketVersioningname-options)
  92. - [.putBucketVersioning(name, status[, options])](#putBucketVersioningname-status-options)
  93. - inventory
  94. - [.getBucketInventory(name, inventoryId[, options])](#getBucketInventoryname-inventoryid-options)
  95. - [.putBucketInventory(name, inventory[, options])](#putBucketInventoryname-inventory-options)
  96. - [.deleteBucketInventory(name, inventoryId[, options])](#deleteBucketInventoryname-inventoryid-options)
  97. - [.listBucketInventory(name, [, options])](#listBucketInventoryname-options)
  98. - worm
  99. - [.abortBucketWorm(name[, options])](#abortBucketWormname-options)
  100. - [.completeBucketWorm(name, wormId[, options])](#completeBucketWormname-wormId-options)
  101. - [.extendBucketWorm(name, wormId, days[, options])](#extendBucketWormname-wormId-days-options)
  102. - [.getBucketWorm(name[, options])](#getBucketWormname-options)
  103. - [.initiateBucketWorm(name, days[, options])](#initiateBucketWormname-days-options)
  104. - [Object Operations](#object-operations)
  105. - [.list(query[, options])](#listquery-options)
  106. - [.listV2(query[, options])](#listV2query-options)
  107. - [.getBucketVersions(query[, options])](#getBucketVersionsquery-options)
  108. - [.put(name, file[, options])](#putname-file-options)
  109. - [.putStream(name, stream[, options])](#putstreamname-stream-options)
  110. - [.append(name, file[, options])](#appendname-file-options)
  111. - [.getObjectUrl(name[, baseUrl])](#getobjecturlname-baseurl)
  112. - [.generateObjectUrl(name[, baseUrl])](#generateobjecturlname-baseurl)
  113. - [.head(name[, options])](#headname-options)
  114. - [.getObjectMeta(name[, options])](#getobjectmetaname-options)
  115. - [.get(name[, file, options])](#getname-file-options)
  116. - [.getStream(name[, options])](#getstreamname-options)
  117. - [.delete(name[, options])](#deletename-options)
  118. - [.copy(name, sourceName[, sourceBucket, options])](#copyname-sourcename-sourcebucket-options)
  119. - [.putMeta(name, meta[, options])](#putmetaname-meta-options)
  120. - [.deleteMulti(names[, options])](#deletemultinames-options)
  121. - [.signatureUrl(name[, options, strictObjectNameValidation])](#signatureurlname-options-strictobjectnamevalidation)
  122. - [.asyncSignatureUrl(name[, options, strictObjectNameValidation])](#asyncsignatureurlname-options-strictobjectnamevalidation)
  123. - [.signatureUrlV4(method, expires[, request, objectName, additionalHeaders])](#signatureurlv4method-expires-request-objectname-additionalheaders)
  124. - [.putACL(name, acl[, options])](#putaclname-acl-options)
  125. - [.getACL(name[, options])](#getaclname-options)
  126. - [.restore(name[, options])](#restorename-options)
  127. - [.putSymlink(name, targetName[, options])](#putsymlinkname-targetname-options)
  128. - [.getSymlink(name[, options])](#getsymlinkname-options)
  129. - [.initMultipartUpload(name[, options])](#initmultipartuploadname-options)
  130. - [.uploadPart(name, uploadId, partNo, file, start, end[, options])](#uploadpartname-uploadid-partno-file-start-end-options)
  131. - [.uploadPartCopy(name, uploadId, partNo, range, sourceData[, options])](#uploadpartcopyname-uploadid-partno-range-sourcedata-options)
  132. - [.completeMultipartUpload(name, uploadId, parts[, options])](#completemultipartuploadname-uploadid-parts-options)
  133. - [.multipartUpload(name, file[, options])](#multipartuploadname-file-options)
  134. - [.multipartUploadCopy(name, sourceData[, options])](#multipartuploadcopyname-sourcedata-options)
  135. - [.listParts(name, uploadId[, query, options])](#listpartsname-uploadid-query-options)
  136. - [.listUploads(query[, options])](#listuploadsquery-options)
  137. - [.abortMultipartUpload(name, uploadId[, options])](#abortmultipartuploadname-uploadid-options)
  138. - [.calculatePostSignature(policy)](#calculatePostSignaturepolicy)
  139. - [.signPostObjectPolicyV4(policy, date)](#signpostobjectpolicyv4policy-date)
  140. - [.getObjectTagging(name, [, options])](#getObjectTaggingname-options)
  141. - [.putObjectTagging(name, tag[, options])](#putObjectTaggingname-tag-options)
  142. - [.deleteObjectTagging(name, [, options])](#deleteObjectTaggingname-options)
  143. - [RTMP Operations](#rtmp-operations)
  144. - [.putChannel(id, conf[, options])](#putchannelid-conf-options)
  145. - [.getChannel(id[, options])](#getchannelid-options)
  146. - [.deleteChannel(id[, options])](#deletechannelid-options)
  147. - [.putChannelStatus(id, status[, options])](#putchannelstatusid-status-options)
  148. - [.getChannelStatus(id[, options])](#getchannelstatusid-options)
  149. - [.listChannels(query[, options])](#listchannelsquery-options)
  150. - [.getChannelHistory(id[, options])](#getchannelhistoryid-options)
  151. - [.createVod(id, name, time[, options])](#createvodid-name-time-options)
  152. - [.getRtmpUrl(channelId[, options])](#getrtmpurlchannelid-options)
  153. - [Create A Image Service Instance](#create-a-image-service-instance)
  154. - [oss.ImageClient(options)](#ossimageclientoptions)
  155. - [Image Operations](#image-operations)
  156. - [imgClient.get(name, file[, options])](#imgclientgetname-file-options)
  157. - [imgClient.getStream(name[, options])](#imgclientgetstreamname-options)
  158. - [imgClient.getExif(name[, options])](#imgclientgetexifname-options)
  159. - [imgClient.getInfo(name[, options])](#imgclientgetinfoname-options)
  160. - [imgClient.putStyle(name, style[, options])](#imgclientputstylename-style-options)
  161. - [imgClient.getStyle(name[, options])](#imgclientgetstylename-options)
  162. - [imgClient.listStyle([options])](#imgclientliststyleoptions)
  163. - [imgClient.deleteStyle(name[, options])](#imgclientdeletestylename-options)
  164. - [imgClient.signatureUrl(name)](#imgclientsignatureurlname)
  165. - [Known Errors](#known-errors)
  166. ## Node Usage
  167. ### Compatibility
  168. - Node: >= 8.0.0
  169. ### Basic usage
  170. 1.install SDK using npm
  171. ```
  172. npm install ali-oss --save
  173. ```
  174. 2.for example:
  175. ```js
  176. const OSS = require('ali-oss');
  177. const store = new OSS({
  178. region: '<oss region>',
  179. accessKeyId: '<Your accessKeyId>',
  180. accessKeySecret: '<Your accessKeySecret>',
  181. bucket: '<Your bucket name>'
  182. });
  183. ```
  184. ## Browser Usage
  185. You can use most of the functionalities of `ali-oss` in browser with
  186. some exceptions:
  187. - put object with streaming: no chunked encoding, we use multipart
  188. upload instead
  189. - get object to local file: we cannot manipulate file system in
  190. browser, we provide signed object url for downloading needs
  191. - bucket operations(listBuckets, putBucketLogging, etc) will fail: OSS
  192. server currently do not support CORS requests for bucket operations
  193. (will probably be fixed later)
  194. ### Compatibility
  195. - IE >= 10 & Edge
  196. - Major versions of Chrome/Firefox/Safari
  197. - Major versions of Android/iOS/WP
  198. > Note: Because some browsers do not support promises, you need to introduce promise compatible libraries.<br>
  199. > For example: IE10 and IE11 need to introduce a promise-polyfill.
  200. ### Setup
  201. #### Bucket setup
  202. As browser-side javascript involves CORS operations. You need to setup
  203. your bucket CORS rules to allow CORS operations:
  204. - set allowed origins to '\*'
  205. - allowed methods to 'PUT, GET, POST, DELETE, HEAD'
  206. - set allowed headers to '\*'
  207. - expose 'ETag' in expose headers
  208. #### STS setup
  209. As we don't want to expose the accessKeyId/accessKeySecret in the
  210. browser, a [common practice][oss-sts] is to use STS to grant temporary
  211. access.
  212. ### Basic usage
  213. Include the sdk lib in the `<script>` tag and you have `OSS` available
  214. for creating client.
  215. ```html
  216. // x.x.x The specific version number represented // we recommend introducing offline resources, because the usability of
  217. online resources depends on the stability of the cdn server.
  218. <!-- Introducing online resources -->
  219. <script src="http://gosspublic.alicdn.com/aliyun-oss-sdk-x.x.x.min.js"></script>
  220. <!-- Introducing offline resources -->
  221. <script src="./aliyun-oss-sdk-x.x.x.min.js"></script>
  222. <script type="text/javascript">
  223. const store = new OSS({
  224. region: 'oss-cn-hangzhou',
  225. accessKeyId: '<access-key-id>',
  226. accessKeySecret: '<access-key-secret>',
  227. bucket: '<bucket-name>',
  228. stsToken: '<security-token>'
  229. });
  230. store
  231. .list()
  232. .then(result => {
  233. console.log('objects: %j', result.objects);
  234. return store.put('my-obj', new OSS.Buffer('hello world'));
  235. })
  236. .then(result => {
  237. console.log('put result: %j', result);
  238. return store.get('my-obj');
  239. })
  240. .then(result => {
  241. console.log('get result: %j', result.content.toString());
  242. });
  243. </script>
  244. ```
  245. The full sample can be found [here][browser-sample].
  246. ### How to build
  247. ```bash
  248. npm run build-dist
  249. ```
  250. And see the build artifacts under `dist/`.
  251. ## Data Regions
  252. [OSS current data regions](https://help.aliyun.com/document_detail/31837.html).
  253. | region | country | city | endpoint | internal endpoint |
  254. | ------------------ | --------- | -------------- | ------------------------------- | ---------------------------------------- |
  255. | oss-cn-hangzhou | China | HangZhou | oss-cn-hangzhou.aliyuncs.com | oss-cn-hangzhou-internal.aliyuncs.com |
  256. | oss-cn-shanghai | China | ShangHai | oss-cn-shanghai.aliyuncs.com | oss-cn-shanghai-internal.aliyuncs.com |
  257. | oss-cn-qingdao | China | QingDao | oss-cn-qingdao.aliyuncs.com | oss-cn-qingdao-internal.aliyuncs.com |
  258. | oss-cn-beijing | China | BeiJing | oss-cn-beijing.aliyuncs.com | oss-cn-beijing-internal.aliyuncs.com |
  259. | oss-cn-shenzhen | China | ShenZhen | oss-cn-shenzhen.aliyuncs.com | oss-cn-shenzhen-internal.aliyuncs.com |
  260. | oss-cn-hongkong | China | HongKong | oss-cn-hongkong.aliyuncs.com | oss-cn-hongkong-internal.aliyuncs.com |
  261. | oss-us-west-1 | US | Silicon Valley | oss-us-west-1.aliyuncs.com | oss-us-west-1-internal.aliyuncs.com |
  262. | oss-ap-southeast-1 | Singapore | Singapore | oss-ap-southeast-1.aliyuncs.com | oss-ap-southeast-1-internal.aliyuncs.com |
  263. ## Create Account
  264. Go to [OSS website](http://www.aliyun.com/product/oss/?lang=en), create a new account for new user.
  265. After account created, you can create the OSS instance and get the `accessKeyId` and `accessKeySecret`.
  266. ## Create A Bucket Instance
  267. Each OSS instance required `accessKeyId`, `accessKeySecret` and `bucket`.
  268. ## oss(options)
  269. Create a Bucket store instance.
  270. options:
  271. - accessKeyId {String} access key you create on aliyun console website
  272. - accessKeySecret {String} access secret you create
  273. - [stsToken] {String} used by temporary authorization, detail [see](https://www.alibabacloud.com/help/doc-detail/32077.htm)
  274. - [refreshSTSToken] {Function} used by auto set `stsToken`、`accessKeyId`、`accessKeySecret` when sts info expires. return value must be object contains `stsToken`、`accessKeyId`、`accessKeySecret`
  275. - [refreshSTSTokenInterval] {number} use time (ms) of refresh STSToken interval it should be less than sts info expire interval, default is 300000ms(5min)
  276. - [bucket] {String} the default bucket you want to access
  277. If you don't have any bucket, please use `putBucket()` create one first.
  278. - [endpoint] {String} oss region domain. It takes priority over `region`. Set as extranet domain name, intranet domain name, accelerated domain name, etc. according to different needs. please see [endpoints](https://www.alibabacloud.com/help/doc-detail/31837.htm)
  279. - [region] {String} the bucket data region location, please see [Data Regions](#data-regions),
  280. default is `oss-cn-hangzhou`.
  281. - [internal] {Boolean} access OSS with aliyun internal network or not, default is `false`.
  282. If your servers are running on aliyun too, you can set `true` to save a lot of money.
  283. - [secure] {Boolean} instruct OSS client to use HTTPS (secure: true) or HTTP (secure: false) protocol.
  284. - [timeout] {String|Number} instance level timeout for all operations, default is `60s`.
  285. - [cname] {Boolean}, default false, access oss with custom domain name. if true, you can fill `endpoint` field with your custom domain name,
  286. - [isRequestPay] {Boolean}, default false, whether request payer function of the bucket is open, if true, will send headers `'x-oss-request-payer': 'requester'` to oss server.
  287. the details you can see [requestPay](https://help.aliyun.com/document_detail/91337.htm)
  288. - [useFetch] {Boolean}, default false, it just work in Browser, if true,it means upload object with
  289. `fetch` mode ,else `XMLHttpRequest`
  290. - [enableProxy] {Boolean}, Enable proxy request, default is false. **_NOTE:_** When enabling proxy request, please ensure that proxy-agent is installed.
  291. - [proxy] {String | Object}, proxy agent uri or options, default is null.
  292. - [retryMax] {Number}, used by auto retry send request count when request error is net error or timeout. **_NOTE:_** Not support `put` with stream, `putStream`, `append` with stream because the stream can only be consumed once
  293. - [maxSockets] {Number} Maximum number of sockets to allow per host. Default is infinity
  294. - [authorizationV4] {Boolean} Use V4 signature. Default is false.
  295. example:
  296. 1. basic usage
  297. ```js
  298. const OSS = require('ali-oss');
  299. const store = new OSS({
  300. accessKeyId: 'your access key',
  301. accessKeySecret: 'your access secret',
  302. bucket: 'your bucket name',
  303. region: 'oss-cn-hangzhou'
  304. });
  305. ```
  306. 2. use accelerate endpoint
  307. - Global accelerate endpoint: oss-accelerate.aliyuncs.com
  308. - Accelerate endpoint of regions outside mainland China: oss-accelerate-overseas.aliyuncs.com
  309. ```js
  310. const OSS = require('ali-oss');
  311. const store = new OSS({
  312. accessKeyId: 'your access key',
  313. accessKeySecret: 'your access secret',
  314. bucket: 'your bucket name',
  315. endpoint: 'oss-accelerate.aliyuncs.com'
  316. });
  317. ```
  318. 3. use custom domain
  319. ```js
  320. const OSS = require('ali-oss');
  321. const store = new OSS({
  322. accessKeyId: 'your access key',
  323. accessKeySecret: 'your access secret',
  324. cname: true,
  325. endpoint: 'your custome domain'
  326. });
  327. ```
  328. 4. use STS and refreshSTSToken
  329. ```js
  330. const OSS = require('ali-oss');
  331. const store = new OSS({
  332. accessKeyId: 'your STS key',
  333. accessKeySecret: 'your STS secret',
  334. stsToken: 'your STS token',
  335. refreshSTSToken: async () => {
  336. const info = await fetch('you sts server');
  337. return {
  338. accessKeyId: info.accessKeyId,
  339. accessKeySecret: info.accessKeySecret,
  340. stsToken: info.stsToken
  341. };
  342. },
  343. refreshSTSTokenInterval: 300000
  344. });
  345. ```
  346. 5. retry request with stream
  347. ```js
  348. for (let i = 0; i <= store.options.retryMax; i++) {
  349. try {
  350. const result = await store.putStream('<example-object>', fs.createReadStream('<example-path>'));
  351. console.log(result);
  352. break; // break if success
  353. } catch (e) {
  354. console.log(e);
  355. }
  356. }
  357. ```
  358. 6. use V4 signature, and use optional additionalHeaders option which type is a string array, and the values inside need to be included in the header.
  359. ```js
  360. const OSS = require('ali-oss');
  361. const store = new OSS({
  362. accessKeyId: 'your access key',
  363. accessKeySecret: 'your access secret',
  364. bucket: 'your bucket name',
  365. region: 'oss-cn-hangzhou',
  366. authorizationV4: true
  367. });
  368. try {
  369. const bucketInfo = await store.getBucketInfo('your bucket name');
  370. console.log(bucketInfo);
  371. } catch (e) {
  372. console.log(e);
  373. }
  374. try {
  375. const putObjectResult = await store.put('your bucket name', 'your object name', {
  376. headers: {
  377. // The headers of this request
  378. header1: 'value1',
  379. header2: 'value2'
  380. },
  381. // The keys of the request headers that need to be calculated into the V4 signature. Please ensure that these additional headers are included in the request headers.
  382. additionalHeaders: ['additional header1', 'additional header2']
  383. });
  384. console.log(putObjectResult);
  385. } catch (e) {
  386. console.log(e);
  387. }
  388. ```
  389. ## Bucket Operations
  390. ### .listBuckets(query[, options])
  391. List buckets in this account.
  392. parameters:
  393. - [query] {Object} query parameters, default is `null`
  394. - [prefix] {String} search buckets using `prefix` key
  395. - [marker] {String} search start from `marker`, including `marker` key
  396. - [max-keys] {String|Number} max buckets, default is `100`, limit to `1000`
  397. - [options] {Object} optional parameters
  398. - [timeout] {Number} the operation timeout
  399. Success will return buckets list on `buckets` properties.
  400. - buckets {Array<BucketMeta>} bucket meta info list
  401. Each `BucketMeta` will contains blow properties:
  402. - name {String} bucket name
  403. - region {String} bucket store data region, e.g.: `oss-cn-hangzhou-a`
  404. - creationDate {String} bucket create GMT date, e.g.: `2015-02-19T08:39:44.000Z`
  405. - storageClass {String} e.g.: `Standard`, `IA`, `Archive`
  406. - owner {Object} object owner, including `id` and `displayName`
  407. - isTruncated {Boolean} truncate or not
  408. - nextMarker {String} next marker string
  409. - res {Object} response info, including
  410. - status {Number} response status
  411. - headers {Object} response headers
  412. - size {Number} response size
  413. - rt {Number} request total use time (ms)
  414. example:
  415. - List top 10 buckets
  416. ```js
  417. store
  418. .listBuckets({
  419. 'max-keys': 10
  420. })
  421. .then(result => {
  422. console.log(result);
  423. });
  424. ```
  425. ### .putBucket(name[, options])
  426. Create a new bucket.
  427. parameters:
  428. - name {String} bucket name
  429. If bucket exists and not belong to current account, will throw BucketAlreadyExistsError.
  430. If bucket not exists, will create a new bucket and set it's ACL.
  431. - [options] {Object} optional parameters
  432. - [acl] {String} include `private`,`public-read`,`public-read-write`
  433. - [storageClass] {String} the storage type include (Standard,IA,Archive)
  434. - [dataRedundancyType] {String} default `LRS`, include `LRS`,`ZRS`
  435. - [timeout] {Number} the operation timeout
  436. Success will return the bucket name on `bucket` properties.
  437. - bucket {String} bucket name
  438. - res {Object} response info, including
  439. - status {Number} response status
  440. - headers {Object} response headers
  441. - size {Number} response size
  442. - rt {Number} request total use time (ms)
  443. example:
  444. - Create a bucket name `helloworld` location on HongKong
  445. ```js
  446. store.putBucket('helloworld').then(result => {
  447. // use it by default
  448. store.useBucket('helloworld');
  449. });
  450. ```
  451. - Create a bucket name `helloworld` location on HongKong StorageClass `Archive`
  452. ```js
  453. await store.putBucket('helloworld', { StorageClass: 'Archive' });
  454. // use it by default
  455. store.useBucket('helloworld');
  456. ```
  457. ### .deleteBucket(name[, options])
  458. Delete an empty bucket.
  459. parameters:
  460. - name {String} bucket name
  461. If bucket is not empty, will throw BucketNotEmptyError.
  462. If bucket is not exists, will throw NoSuchBucketError.
  463. - [options] {Object} optional parameters
  464. - [timeout] {Number} the operation timeout
  465. Success will return:
  466. - res {Object} response info, including
  467. - status {Number} response status
  468. - headers {Object} response headers
  469. - size {Number} response size
  470. - rt {Number} request total use time (ms)
  471. example:
  472. - Delete the exists 'helloworld' bucket on 'oss-cn-hongkong'
  473. ```js
  474. store.deleteBucket('helloworld').then(result => {});
  475. ```
  476. ### .useBucket(name)
  477. Use the bucket.
  478. parameters:
  479. - name {String} bucket name
  480. example:
  481. - Use `helloworld` as the default bucket
  482. ```js
  483. store.useBucket('helloworld');
  484. ```
  485. ### .getBucketInfo(name)
  486. Get bucket information,include CreationDate、ExtranetEndpoint、IntranetEndpoint、Location、Name、StorageClass、
  487. Owner、AccessControlList、Versioning
  488. parameters:
  489. - name {String} bucket name
  490. example:
  491. - Use `helloworld` as the default bucket
  492. ```js
  493. store.getBucketInfo('helloworld').then(res => {
  494. console.log(res.bucket);
  495. });
  496. ```
  497. ### .getBucketStat(name)
  498. Call the GetBucketStat interface to get the storage capacity of the specified storage space (Bucket) and the number of files (Object).
  499. Calling this interface requires the oss:GetBucketStat permission.
  500. The data obtained by calling this interface is not real-time data and may be delayed for more than an hour.
  501. The point in time of the stored information obtained by calling this interface is not guaranteed to be up-to-date, i.e. the LastModifiedTime field returned by a later call to this interface may be smaller than the LastModifiedTime field returned by a previous call to this interface.
  502. parameters:
  503. - name {String} bucket name
  504. Success will return:
  505. - stat {Object} container for the BucketStat structure:
  506. - Storage {String} the total storage capacity of the Bucket, in bytes.
  507. - ObjectCount {String} total number of Objects in the Bucket。
  508. - MultipartUploadCount {String} the number of Multipart Uploads in the Bucket that have been initialized but not yet completed (Complete) or not yet aborted (Abort).
  509. - LiveChannelCount {String} the number of Live Channels in the Bucket.
  510. - LastModifiedTime {String} the point in time, in timestamps, when the storage information was retrieved.
  511. - StandardStorage {String} the amount of storage of the standard storage type, in bytes.
  512. - StandardObjectCount {String} the number of objects of the standard storage type.
  513. - InfrequentAccessStorage {String} the amount of billed storage for the low-frequency storage type, in bytes.
  514. - InfrequentAccessRealStorage {String} the actual storage amount of the low-frequency storage type, in bytes.
  515. - InfrequentAccessObjectCount {String} the number of Objects of the low-frequency storage type.
  516. - ArchiveStorage {String} the amount of billed storage for the archive storage type, in bytes.
  517. - ArchiveRealStorage {String} the actual storage amount of the archive storage type, in bytes.
  518. - ArchiveObjectCount {String} the number of objects of the archive storage type.
  519. - ColdArchiveStorage {String} the amount of billed storage for the cold archive storage type, in bytes.
  520. - ColdArchiveRealStorage {String} the actual storage amount in bytes for the cold archive storage type.
  521. - ColdArchiveObjectCount {String} the number of objects of the cold archive storage type.
  522. - res {Object} response info, including
  523. - status {Number} response status
  524. - headers {Object} response headers
  525. - size {Number} response size
  526. - rt {Number} request total use time (ms)
  527. example:
  528. - If you don't fill in the name, the default is the bucket defined during initialization.
  529. ```js
  530. store.getBucketStat().then(res => console.log(res));
  531. ```
  532. ### .getBucketLocation(name)
  533. Get bucket location
  534. parameters:
  535. - name {String} bucket name
  536. example:
  537. - Use `helloworld` as the default bucket
  538. ```js
  539. store.getBucketLocation('helloworld').then(res => {
  540. console.log(res.location);
  541. });
  542. ```
  543. ---
  544. ### .putBucketACL(name, acl[, options])
  545. Update the bucket ACL.
  546. parameters:
  547. - name {String} bucket name
  548. - acl {String} access control list, current available: `public-read-write`, `public-read` and `private`
  549. - [options] {Object} optional parameters
  550. - [timeout] {Number} the operation timeout
  551. Success will return:
  552. - res {Object} response info, including
  553. - status {Number} response status
  554. - headers {Object} response headers
  555. - size {Number} response size
  556. - rt {Number} request total use time (ms)
  557. example:
  558. - Set bucket `helloworld` to `public-read-write`
  559. ```js
  560. store.putBucketACL('helloworld', 'public-read-write').then(result => {});
  561. ```
  562. ### .getBucketACL(name[, options])
  563. Get the bucket ACL.
  564. parameters:
  565. - name {String} bucket name
  566. - [options] {Object} optional parameters
  567. - [timeout] {Number} the operation timeout
  568. Success will return:
  569. - acl {String} acl settiongs string
  570. - res {Object} response info, including
  571. - status {Number} response status
  572. - headers {Object} response headers
  573. - size {Number} response size
  574. - rt {Number} request total use time (ms)
  575. example:
  576. - Get bucket `helloworld`
  577. ```js
  578. store.getBucketACL('helloworld').then(result => {
  579. console.log(result.acl);
  580. });
  581. ```
  582. ---
  583. ### .putBucketLogging(name, prefix[, options])
  584. Update the bucket logging settings.
  585. Log file will create every one hour and name format: `<prefix><bucket>-YYYY-mm-DD-HH-MM-SS-UniqueString`.
  586. parameters:
  587. - name {String} bucket name
  588. - [prefix] {String} prefix path name to store the log files
  589. - [options] {Object} optional parameters
  590. - [timeout] {Number} the operation timeout
  591. Success will return:
  592. - res {Object} response info, including
  593. - status {Number} response status
  594. - headers {Object} response headers
  595. - size {Number} response size
  596. - rt {Number} request total use time (ms)
  597. example:
  598. - Enable bucket `helloworld` logging and save with prefix `logs/`
  599. ```js
  600. store.putBucketLogging('helloworld', 'logs/').then(result => {});
  601. ```
  602. ### .getBucketLogging(name[, options])
  603. Get the bucket logging settings.
  604. parameters:
  605. - name {String} bucket name
  606. - [options] {Object} optional parameters
  607. - [timeout] {Number} the operation timeout
  608. Success will return:
  609. - enable {Boolean} enable logging or not
  610. - prefix {String} prefix path name to store the log files, maybe `null`
  611. - res {Object} response info, including
  612. - status {Number} response status
  613. - headers {Object} response headers
  614. - size {Number} response size
  615. - rt {Number} request total use time (ms)
  616. example:
  617. - Get bucket `helloworld` logging settings
  618. ```js
  619. store.getBucketLogging('helloworld').then(result => {
  620. console.log(result.enable, result.prefix);
  621. });
  622. ```
  623. ### .deleteBucketLogging(name[, options])
  624. Delete the bucket logging settings.
  625. parameters:
  626. - name {String} bucket name
  627. - [options] {Object} optional parameters
  628. - [timeout] {Number} the operation timeout
  629. Success will return:
  630. - res {Object} response info, including
  631. - status {Number} response status
  632. - headers {Object} response headers
  633. - size {Number} response size
  634. - rt {Number} request total use time (ms)
  635. ---
  636. ### .putBucketWebsite(name, config[, options])
  637. Set the bucket as a static website.
  638. parameters:
  639. - name {String} bucket name
  640. - config {Object} website config, contains blow properties:
  641. - index {String} default page, e.g.: `index.html`
  642. - [error] {String} error page, e.g.: 'error.html'
  643. - [supportSubDir] {String} default vaule false
  644. - [type] {String} default value 0
  645. - [routingRules] {Array} RoutingRules
  646. - [options] {Object} optional parameters
  647. - [timeout] {Number} the operation timeout
  648. Success will return:
  649. - res {Object} response info, including
  650. - status {Number} response status
  651. - headers {Object} response headers
  652. - size {Number} response size
  653. - rt {Number} request total use time (ms)
  654. example:
  655. ```js
  656. store
  657. .putBucketWebsite('hello', {
  658. index: 'index.html'
  659. })
  660. .then(result => {});
  661. ```
  662. ### .getBucketWebsite(name[, options])
  663. Get the bucket website config.
  664. parameters:
  665. - name {String} bucket name
  666. - [options] {Object} optional parameters
  667. - [timeout] {Number} the operation timeout
  668. Success will return:
  669. - index {String} index page
  670. - error {String} error page, maybe `null`
  671. - supportSubDir {String}
  672. - type {String}
  673. - routingRules {Array}
  674. - res {Object} response info, including
  675. - status {Number} response status
  676. - headers {Object} response headers
  677. - size {Number} response size
  678. - rt {Number} request total use time (ms)
  679. ### .deleteBucketWebsite(name[, options])
  680. Delete the bucket website config.
  681. parameters:
  682. - name {String} bucket name
  683. - [options] {Object} optional parameters
  684. - [timeout] {Number} the operation timeout
  685. Success will return:
  686. - res {Object} response info, including
  687. - status {Number} response status
  688. - headers {Object} response headers
  689. - size {Number} response size
  690. - rt {Number} request total use time (ms)
  691. ---
  692. ### .putBucketReferer(name, allowEmpty, referers[, options])
  693. Set the bucket request `Referer` white list.
  694. parameters:
  695. - name {String} bucket name
  696. - allowEmpty {Boolean} allow empty request referer or not
  697. - referers {Array<String>} `Referer` white list, e.g.:
  698. ```js
  699. ['https://npm.taobao.org', 'http://cnpmjs.org'];
  700. ```
  701. - [options] {Object} optional parameters
  702. - [timeout] {Number} the operation timeout
  703. Success will return:
  704. - res {Object} response info, including
  705. - status {Number} response status
  706. - headers {Object} response headers
  707. - size {Number} response size
  708. - rt {Number} request total use time (ms)
  709. example:
  710. ```js
  711. store.putBucketReferer('hello', false, ['https://npm.taobao.org', 'http://cnpmjs.org']).then(result => {});
  712. ```
  713. ### .getBucketReferer(name[, options])
  714. Get the bucket request `Referer` white list.
  715. parameters:
  716. - name {String} bucket name
  717. - [options] {Object} optional parameters
  718. - [timeout] {Number} the operation timeout
  719. Success will return:
  720. - allowEmpty {Boolean} allow empty request referer or not
  721. - referers {Array<String>} `Referer` white list
  722. - res {Object} response info, including
  723. - status {Number} response status
  724. - headers {Object} response headers
  725. - size {Number} response size
  726. - rt {Number} request total use time (ms)
  727. ### .deleteBucketReferer(name[, options])
  728. Delete the bucket request `Referer` white list.
  729. parameters:
  730. - name {String} bucket name
  731. - [options] {Object} optional parameters
  732. - [timeout] {Number} the operation timeout
  733. Success will return:
  734. - res {Object} response info, including
  735. - status {Number} response status
  736. - headers {Object} response headers
  737. - size {Number} response size
  738. - rt {Number} request total use time (ms)
  739. ---
  740. ### .putBucketLifecycle(name, rules[, options])
  741. Set the bucket object lifecycle.
  742. parameters:
  743. - name {String} bucket name
  744. - rules {Array<Rule>} rule config list, each `Rule` will contains blow properties:
  745. - [id] {String} rule id, if not set, OSS will auto create it with random string.
  746. - prefix {String} store prefix
  747. - status {String} rule status, allow values: `Enabled` or `Disabled`
  748. - [expiration] {Object} specifies the expiration attribute of the lifecycle rules for the object.
  749. - [days] {Number|String} expire after the `days`
  750. - [createdBeforeDate] {String} expire date, e.g.: `2022-10-11T00:00:00.000Z`
  751. - [expiredObjectDeleteMarker] {String} value `true`
  752. `createdBeforeDate` and `days` and `expiredObjectDeleteMarker` must have one.
  753. - [abortMultipartUpload] {Object} Specifies the expiration attribute of the multipart upload tasks that are not complete.
  754. - [days] {Number|String} expire after the `days`
  755. - [createdBeforeDate] {String} expire date, e.g.: `2022-10-11T00:00:00.000Z`
  756. `createdBeforeDate` and `days` must have one.
  757. - [transition] {Object} Specifies the time when an object is converted to the IA or archive storage class during a valid life cycle.
  758. - storageClass {String} Specifies the storage class that objects that conform to the rule are converted into. allow values: `IA` or `Archive` or `ColdArchive` or `DeepColdArchive`
  759. - [days] {Number|String} expire after the `days`
  760. - [createdBeforeDate] {String} expire date, e.g.: `2022-10-11T00:00:00.000Z`
  761. `createdBeforeDate` and `days` must have one.
  762. - [noncurrentVersionTransition] {Object} Specifies the time when an object is converted to the IA or archive storage class during a valid life cycle.
  763. - storageClass {String} Specifies the storage class that history objects that conform to the rule are converted into. allow values: `IA` or `Archive` or `ColdArchive` or `DeepColdArchive`
  764. - noncurrentDays {String} expire after the `noncurrentDays`
  765. `expiration``abortMultipartUpload``transition``noncurrentVersionTransition` must have one.
  766. - [noncurrentVersionExpiration] {Object} specifies the expiration attribute of the lifecycle rules for the history object.
  767. - noncurrentDays {String} expire after the `noncurrentDays`
  768. - [tag] {Object} Specifies the object tag applicable to a rule. Multiple tags are supported.
  769. - key {String} Indicates the tag key.
  770. - value {String} Indicates the tag value.
  771. `tag` cannot be used with `abortMultipartUpload`
  772. - [options] {Object} optional parameters
  773. - [timeout] {Number} the operation timeout
  774. Success will return:
  775. - res {Object} response info, including
  776. - status {Number} response status
  777. - headers {Object} response headers
  778. - size {Number} response size
  779. - rt {Number} request total use time (ms)
  780. example:
  781. ```js
  782. store
  783. .putBucketLifecycle('hello', [
  784. {
  785. id: 'delete after one day',
  786. prefix: 'logs/',
  787. status: 'Enabled',
  788. days: 1
  789. },
  790. {
  791. prefix: 'logs2/',
  792. status: 'Disabled',
  793. date: '2022-10-11T00:00:00.000Z'
  794. }
  795. ])
  796. .then(result => {});
  797. ```
  798. example: for history with noncurrentVersionExpiration
  799. ```js
  800. const result = await store.putBucketLifecycle(bucket, [
  801. {
  802. id: 'expiration1',
  803. prefix: 'logs/',
  804. status: 'Enabled',
  805. expiration: {
  806. days: '1'
  807. },
  808. noncurrentVersionExpiration: {
  809. noncurrentDays: '1'
  810. }
  811. }
  812. ]);
  813. console.log(result);
  814. ```
  815. example: for history with expiredObjectDeleteMarker
  816. ```js
  817. const result = await store.putBucketLifecycle(bucket, [
  818. {
  819. id: 'expiration1',
  820. prefix: 'logs/',
  821. status: 'Enabled',
  822. expiration: {
  823. expiredObjectDeleteMarker: 'true'
  824. },
  825. noncurrentVersionExpiration: {
  826. noncurrentDays: '1'
  827. }
  828. }
  829. ]);
  830. console.log(result);
  831. ```
  832. example: for history with noncurrentVersionTransition
  833. ```js
  834. const result = await store.putBucketLifecycle(bucket, [
  835. {
  836. id: 'expiration1',
  837. prefix: 'logs/',
  838. status: 'Enabled',
  839. noncurrentVersionTransition: {
  840. noncurrentDays: '10',
  841. storageClass: 'IA'
  842. }
  843. }
  844. ]);
  845. console.log(result);
  846. ```
  847. ### .getBucketLifecycle(name[, options])
  848. Get the bucket object lifecycle.
  849. parameters:
  850. - name {String} bucket name
  851. - [options] {Object} optional parameters
  852. - [timeout] {Number} the operation timeout
  853. Success will return:
  854. - rules {Array<Rule>} the lifecycle rule list
  855. - res {Object} response info, including
  856. - status {Number} response status
  857. - headers {Object} response headers
  858. - size {Number} response size
  859. - rt {Number} request total use time (ms)
  860. ### .deleteBucketLifecycle(name[, options])
  861. Delete the bucket object lifecycle.
  862. parameters:
  863. - name {String} bucket name
  864. - [options] {Object} optional parameters
  865. - [timeout] {Number} the operation timeout
  866. Success will return:
  867. - res {Object} response info, including
  868. - status {Number} response status
  869. - headers {Object} response headers
  870. - size {Number} response size
  871. - rt {Number} request total use time (ms)
  872. ---
  873. ### .putBucketCORS(name, rules[, options])
  874. Set CORS rules of the bucket object
  875. parameters:
  876. - name {String} bucket name
  877. - rules {Array<Rule>} rule config list, each `Rule` will contains below properties:
  878. - allowedOrigin {String/Array} configure for Access-Control-Allow-Origin header
  879. - allowedMethod {String/Array} configure for Access-Control-Allow-Methods header
  880. - [allowedHeader] {String/Array} configure for Access-Control-Allow-Headers header
  881. - [exposeHeader] {String/Array} configure for Access-Control-Expose-Headers header
  882. - [maxAgeSeconds] {String} configure for Access-Control-Max-Age header
  883. - [options] {Object} optional parameters
  884. - [timeout] {Number} the operation timeout
  885. Success will return:
  886. - res {Object} response info, including
  887. - status {Number} response status
  888. - headers {Object} response headers
  889. - size {Number} response size
  890. - rt {Number} request total use time (ms)
  891. example:
  892. ```js
  893. store
  894. .putBucketCORS('hello', [
  895. {
  896. allowedOrigin: '*',
  897. allowedMethod: ['GET', 'HEAD']
  898. }
  899. ])
  900. .then(result => {});
  901. ```
  902. ### .getBucketCORS(name[, options])
  903. Get CORS rules of the bucket object.
  904. parameters:
  905. - name {String} bucket name
  906. - [options] {Object} optional parameters
  907. - [timeout] {Number} the operation timeout
  908. Success will return:
  909. - rules {Array<Rule>} the CORS rule list
  910. - res {Object} response info, including
  911. - status {Number} response status
  912. - headers {Object} response headers
  913. - size {Number} response size
  914. - rt {Number} request total use time (ms)
  915. ### .deleteBucketCORS(name[, options])
  916. Delete CORS rules of the bucket object.
  917. parameters:
  918. - name {String} bucket name
  919. - [options] {Object} optional parameters
  920. - [timeout] {Number} the operation timeout
  921. Success will return:
  922. - res {Object} response info, including
  923. - status {Number} response status
  924. - headers {Object} response headers
  925. - size {Number} response size
  926. - rt {Number} request total use time (ms)
  927. ### .getBucketRequestPayment(bucketName[, options])
  928. get RequestPayment value of the bucket object.
  929. parameters:
  930. - bucketName {String} bucket name
  931. - [options] {Object} optional parameters
  932. Success will return:
  933. - status {Number} response status
  934. - payer {String} payer, BucketOwner or Requester
  935. - res {Object} response info, including
  936. - data {Buffer} xml
  937. ---
  938. ### .putBucketRequestPayment(bucketName, payer[, options])
  939. put RequestPayment value of the bucket object.
  940. parameters:
  941. - bucketName {String}
  942. - payer {String} payer
  943. - [options] {Object} optional parameters
  944. Success will return:
  945. - status {Number} response status
  946. - res {Object} response info
  947. ---
  948. ### .putBucketEncryption(name, rules)
  949. put BucketEncryption value of the bucket object.
  950. parameters:
  951. - name {String} bucket name
  952. - [rules] {Object} parameters
  953. - SSEAlgorithm {String} encryption type, expect AES256 or KMS
  954. - {KMSMasterKeyID} {String} needed when encryption type is KMS
  955. Success will return:
  956. - status {Number} response status
  957. - res {Object} response info
  958. ---
  959. ### .getBucketEncryption(name)
  960. get BucketEncryption rule value of the bucket object.
  961. parameters:
  962. - name {String} bucket name
  963. Success will return:
  964. - status {Number} response status
  965. - res {Object} response info
  966. - encryption {Object} rules
  967. - SSEAlgorithm {String} encryption type, AES256 or KMS
  968. - {KMSMasterKeyID} {String} will be return when encryption type is KMS
  969. ---
  970. ### .deleteBucketEncryption(name)
  971. delete BucketEncryption rule value of the bucket object.
  972. parameters:
  973. - name {String} bucket name
  974. Success will return:
  975. - status {Number} response status
  976. - res {Object} response info
  977. ---
  978. ### .putBucketTags(name, tag[, options])
  979. Adds tags for a bucket or modify the tags for a bucket.
  980. parameters:
  981. - name {String} the object name
  982. - tag {Object} tag, eg. `{var1: value1,var2:value2}`
  983. - [options] {Object} optional args
  984. Success will return:
  985. - status {Number} response status
  986. - res {Object} response info
  987. ---
  988. ### .getBucketTags(name[, options])
  989. Obtains the tags for a bucket.
  990. parameters:
  991. - name {String} the object name
  992. - [options] {Object} optional args
  993. Success will return:
  994. - tag {Object} the tag of object
  995. - res {Object} response info
  996. ---
  997. ### .deleteBucketTags(name[, options])
  998. Deletes the tags added for a bucket.
  999. parameters:
  1000. - name {String} the object name
  1001. - [options] {Object} optional args
  1002. Success will return:
  1003. - status {Number} response status
  1004. - res {Object} response info
  1005. ---
  1006. ### .putBucketPolicy(name, policy[, options])
  1007. Adds or modify policy for a bucket.
  1008. parameters:
  1009. - name {String} the bucket name
  1010. - policy {Object} bucket policy
  1011. - [options] {Object} optional args
  1012. Success will return:
  1013. - status {Number} response status
  1014. - res {Object} response info
  1015. example:
  1016. ```js
  1017. const policy = {
  1018. Version: '1',
  1019. Statement: [
  1020. {
  1021. Action: ['oss:PutObject', 'oss:GetObject'],
  1022. Effect: 'Deny',
  1023. Principal: ['1234567890'],
  1024. Resource: ['acs:oss:*:1234567890:*/*']
  1025. }
  1026. ]
  1027. };
  1028. const result = await store.putBucketPolicy(bucket, policy);
  1029. console.log(result);
  1030. ```
  1031. ---
  1032. ### .getBucketPolicy(name[, options])
  1033. Obtains the policy for a bucket.
  1034. parameters:
  1035. - name {String} the bucket name
  1036. - [options] {Object} optional args
  1037. Success will return:
  1038. - policy {Object} the policy of bucket, if not exist, the value is null
  1039. - res {Object} response info
  1040. - status {Number} response status
  1041. ---
  1042. ### .deleteBucketPolicy(name[, options])
  1043. Deletes the policy added for a bucket.
  1044. parameters:
  1045. - name {String} the bucket name
  1046. - [options] {Object} optional args
  1047. Success will return:
  1048. - status {Number} response status
  1049. - res {Object} response info
  1050. ---
  1051. ### .getBucketVersioning(name[, options])
  1052. Obtains the version status of an object
  1053. parameters:
  1054. - name {String} the bucket name
  1055. - [options] {Object} optional args
  1056. Success will return:
  1057. - status {Number} response status
  1058. - versionStatus {String | undefined} version status, `Suspended` or `Enabled`. default value: `undefined`
  1059. - res {Object} response info
  1060. ---
  1061. ### .putBucketVersioning(name, status[, options])
  1062. set the version status of an object
  1063. parameters:
  1064. - name {String} the bucket name
  1065. - status {String} version status, allow values: `Enabled` or `Suspended`
  1066. - [options] {Object} optional args
  1067. Success will return:
  1068. - status {Number} response status
  1069. - res {Object} response info
  1070. ---
  1071. ### .getBucketInventory(name, inventoryId[, options])
  1072. get bucket inventory by inventory-id
  1073. parameters:
  1074. - name {String} the bucket name
  1075. - inventoryId {String} inventory-id
  1076. - [options] {Object} optional args
  1077. Success will return:
  1078. - inventory {Inventory}
  1079. - status {Number} response status
  1080. - res {Object} response info
  1081. ```js
  1082. async function getBucketInventoryById() {
  1083. try {
  1084. const result = await store.getBucketInventory('bucket', 'inventoryid');
  1085. console.log(result.inventory);
  1086. } catch (err) {
  1087. console.log(err);
  1088. }
  1089. }
  1090. getBucketInventoryById();
  1091. ```
  1092. ### putBucketInventory(name, inventory[, options])
  1093. set bucket inventory
  1094. parameters:
  1095. - name {String} the bucket name
  1096. - inventory {Inventory} inventory config
  1097. - [options] {Object} optional args
  1098. Success will return:
  1099. - status {Number} response status
  1100. - res {Object} response info
  1101. ```ts
  1102. type Field =
  1103. 'Size | LastModifiedDate | ETag | StorageClass | IsMultipartUploaded | EncryptionStatus | ObjectAcl | TaggingCount | ObjectType | Crc64';
  1104. interface Inventory {
  1105. id: string;
  1106. isEnabled: true | false;
  1107. prefix?: string;
  1108. OSSBucketDestination: {
  1109. format: 'CSV';
  1110. accountId: string;
  1111. rolename: string;
  1112. bucket: string;
  1113. prefix?: string;
  1114. encryption?:
  1115. | { 'SSE-OSS': '' }
  1116. | {
  1117. 'SSE-KMS': {
  1118. keyId: string;
  1119. };
  1120. };
  1121. };
  1122. frequency: 'Daily' | 'Weekly';
  1123. includedObjectVersions: 'Current' | 'All';
  1124. optionalFields?: {
  1125. field?: Field[];
  1126. };
  1127. }
  1128. ```
  1129. ```js
  1130. const inventory = {
  1131. id: 'default',
  1132. isEnabled: false, // `true` | `false`
  1133. prefix: 'ttt', // filter prefix
  1134. OSSBucketDestination: {
  1135. format: 'CSV',
  1136. accountId: '1817184078010220',
  1137. rolename: 'AliyunOSSRole',
  1138. bucket: 'your bucket',
  1139. prefix: 'test'
  1140. //encryption: {'SSE-OSS': ''},
  1141. /*
  1142. encryption: {
  1143. 'SSE-KMS': {
  1144. keyId: 'test-kms-id';
  1145. };,
  1146. */
  1147. },
  1148. frequency: 'Daily', // `WEEKLY` | `Daily`
  1149. includedObjectVersions: 'All', // `All` | `Current`
  1150. optionalFields: {
  1151. field: [
  1152. 'Size',
  1153. 'LastModifiedDate',
  1154. 'ETag',
  1155. 'StorageClass',
  1156. 'IsMultipartUploaded',
  1157. 'EncryptionStatus',
  1158. 'ObjectAcl',
  1159. 'TaggingCount',
  1160. 'ObjectType',
  1161. 'Crc64'
  1162. ]
  1163. }
  1164. };
  1165. async function putInventory() {
  1166. const bucket = 'Your Bucket Name';
  1167. try {
  1168. await store.putBucketInventory(bucket, inventory);
  1169. } catch (err) {
  1170. console.log(err);
  1171. }
  1172. }
  1173. putInventory();
  1174. ```
  1175. ### deleteBucketInventory(name, inventoryId[, options])
  1176. delete bucket inventory by inventory-id
  1177. parameters:
  1178. - name {String} the bucket name
  1179. - inventoryId {String} inventory-id
  1180. - [options] {Object} optional args
  1181. Success will return:
  1182. - status {Number} response status
  1183. - res {Object} response info
  1184. ### listBucketInventory(name[, options])
  1185. list bucket inventory
  1186. parameters:
  1187. - name {String} the bucket name
  1188. - [options] {Object} optional args
  1189. - continuationToken used by search next page
  1190. Success will return:
  1191. - status {Number} response status
  1192. - res {Object} response info
  1193. example:
  1194. ```js
  1195. async function listBucketInventory() {
  1196. const bucket = 'Your Bucket Name';
  1197. let nextContinuationToken;
  1198. // list all inventory of the bucket
  1199. do {
  1200. const result = await store.listBucketInventory(bucket, nextContinuationToken);
  1201. console.log(result.inventoryList);
  1202. nextContinuationToken = result.nextContinuationToken;
  1203. } while (nextContinuationToken);
  1204. }
  1205. listBucketInventory();
  1206. ```
  1207. ### .abortBucketWorm(name[, options])
  1208. used to delete an unlocked retention policy.
  1209. parameters:
  1210. - name {String} the bucket name
  1211. - [options] {Object} optional args
  1212. Success will return:
  1213. - status {Number} response status
  1214. - res {Object} response info
  1215. ---
  1216. ### .completeBucketWorm(name, wormId[, options])
  1217. used to lock a retention policy.
  1218. parameters:
  1219. - name {String} the bucket name
  1220. - wormId {String} worm id
  1221. - [options] {Object} optional args
  1222. Success will return:
  1223. - status {Number} response status
  1224. - res {Object} response info
  1225. ---
  1226. ### .extendBucketWorm(name, wormId, days[, options])
  1227. used to extend the retention period of objects in a bucket whose retention policy is locked.
  1228. parameters:
  1229. - name {String} the bucket name
  1230. - wormId {String} worm id
  1231. - days {String | Number} retention days
  1232. - [options] {Object} optional args
  1233. Success will return:
  1234. - status {Number} response status
  1235. - res {Object} response info
  1236. ---
  1237. ### .getBucketWorm(name[, options])
  1238. used to query the retention policy information of the specified bucket.
  1239. parameters:
  1240. - name {String} the bucket name
  1241. - [options] {Object} optional args
  1242. Success will return:
  1243. - wormId {String} worm id
  1244. - state {String} `Locked` or `InProgress`
  1245. - days {String} retention days
  1246. - creationDate {String}
  1247. - status {Number} response status
  1248. - res {Object} response info
  1249. ---
  1250. ### .initiateBucketWorm(name, days[, options])
  1251. create a retention policy.
  1252. parameters:
  1253. - name {String} the bucket name
  1254. - days {String | Number}} set retention days
  1255. - [options] {Object} optional args
  1256. Success will return:
  1257. - wormId {String} worm id
  1258. - status {Number} response status
  1259. - res {Object} response info
  1260. ---
  1261. ## Object Operations
  1262. All operations function return Promise, except `signatureUrl`.
  1263. ### .put(name, file[, options])
  1264. Add an object to the bucket.
  1265. parameters:
  1266. - name {String} object name store on OSS
  1267. - file {String|Buffer|ReadStream|File(only support Browser)|Blob(only support Browser)} object local path, content buffer or ReadStream content instance use in Node, Blob and html5 File
  1268. - [options] {Object} optional parameters
  1269. - [timeout] {Number} the operation timeout (ms)
  1270. - [mime] {String} custom mime, will send with `Content-Type` entity header
  1271. - [meta] {Object} user meta, will send with `x-oss-meta-` prefix string
  1272. e.g.: `{ uid: 123, pid: 110 }`
  1273. - [callback] {Object} The callback parameter is composed of a JSON string encoded in Base64,detail [see](https://www.alibabacloud.com/help/doc-detail/31989.htm)<br>
  1274. - url {String} After a file is uploaded successfully, the OSS sends a callback request to this URL.
  1275. - [host] {String} The host header value for initiating callback requests.
  1276. - body {String} The value of the request body when a callback is initiated, for example, `key=${key}&etag=${etag}&my_var=${x:my_var}`.
  1277. - [contentType] {String} The Content-Type of the callback requests initiatiated, It supports application/x-www-form-urlencoded and application/json, and the former is the default value.
  1278. - [callbackSNI] {Boolean} Specifies whether OSS sends Server Name Indication (SNI) to the origin address specified by callbackUrl when a callback request is initiated from the client.
  1279. - [customValue] {Object} Custom parameters are a map of key-values<br>
  1280. e.g.:
  1281. ```js
  1282. var customValue = { var1: 'value1', var2: 'value2' };
  1283. ```
  1284. - [headers] {Object} extra headers
  1285. - 'Cache-Control' cache control for download, e.g.: `Cache-Control: public, no-cache`
  1286. - 'Content-Disposition' object name for download, e.g.: `Content-Disposition: somename`
  1287. - 'Content-Encoding' object content encoding for download, e.g.: `Content-Encoding: gzip`
  1288. - 'Expires' expires time for download, an absolute date and time. e.g.: `Tue, 08 Dec 2020 13:49:43 GMT`
  1289. - See more: [PutObject](https://help.aliyun.com/document_detail/31978.html#title-yxe-96d-x61)
  1290. - [disabledMD5] {Boolean} default true, it just work in Browser. if false,it means that MD5 is automatically calculated for uploaded files. **_NOTE:_** Synchronous computing tasks will block the main process
  1291. Success will return the object information.
  1292. object:
  1293. - name {String} object name
  1294. - data {Object} callback server response data, sdk use JSON.parse() return
  1295. - res {Object} response info, including
  1296. - status {Number} response status
  1297. - headers {Object} response headers
  1298. - size {Number} response size
  1299. - rt {Number} request total use time (ms)
  1300. example:
  1301. - Add an object through local file path
  1302. ```js
  1303. const filepath = '/home/ossdemo/demo.txt';
  1304. store.put('ossdemo/demo.txt', filepath).then((result) => {
  1305. console.log(result);
  1306. });
  1307. // {
  1308. // name: 'ossdemo/demo.txt',
  1309. // res: {
  1310. // status: 200,
  1311. // headers: {
  1312. // date: 'Tue, 17 Feb 2015 13:28:17 GMT',
  1313. // 'content-length': '0',
  1314. // connection: 'close',
  1315. // etag: '"BF7A03DA01440845BC5D487B369BC168"',
  1316. // server: 'AliyunOSS',
  1317. // 'x-oss-request-id': '54E341F1707AA0275E829244'
  1318. // },
  1319. // size: 0,
  1320. // rt: 92
  1321. // }
  1322. // }
  1323. ```
  1324. - Add an object through content buffer
  1325. ```js
  1326. store.put('ossdemo/buffer', Buffer.from('foo content')).then((result) => {
  1327. console.log(result);
  1328. });
  1329. // {
  1330. // name: 'ossdemo/buffer',
  1331. // url: 'http://demo.oss-cn-hangzhou.aliyuncs.com/ossdemo/buffer',
  1332. // res: {
  1333. // status: 200,
  1334. // headers: {
  1335. // date: 'Tue, 17 Feb 2015 13:28:17 GMT',
  1336. // 'content-length': '0',
  1337. // connection: 'close',
  1338. // etag: '"xxx"',
  1339. // server: 'AliyunOSS',
  1340. // 'x-oss-request-id': '54E341F1707AA0275E829243'
  1341. // },
  1342. // size: 0,
  1343. // rt: 92
  1344. // }
  1345. // }
  1346. ```
  1347. - Add an object through readstream
  1348. ```js
  1349. const filepath = '/home/ossdemo/demo.txt';
  1350. store.put('ossdemo/readstream.txt', fs.createReadStream(filepath)).then((result) => {
  1351. console.log(result);
  1352. });
  1353. // {
  1354. // name: 'ossdemo/readstream.txt',
  1355. // url: 'http://demo.oss-cn-hangzhou.aliyuncs.com/ossdemo/readstream.txt',
  1356. // res: {
  1357. // status: 200,
  1358. // headers: {
  1359. // date: 'Tue, 17 Feb 2015 13:28:17 GMT',
  1360. // 'content-length': '0',
  1361. // connection: 'close',
  1362. // etag: '"BF7A03DA01440845BC5D487B369BC168"',
  1363. // server: 'AliyunOSS',
  1364. // 'x-oss-request-id': '54E341F1707AA0275E829242'
  1365. // },
  1366. // size: 0,
  1367. // rt: 92
  1368. // }
  1369. // }
  1370. ```
  1371. ### .putStream(name, stream[, options])
  1372. Add a stream object to the bucket.
  1373. parameters:
  1374. - name {String} object name store on OSS
  1375. - stream {ReadStream} object ReadStream content instance
  1376. - [options] {Object} optional parameters
  1377. - [contentLength] {Number} the stream length, `chunked encoding` will be used if absent
  1378. - [timeout] {Number} the operation timeout
  1379. - [mime] {String} custom mime, will send with `Content-Type` entity header
  1380. - [meta] {Object} user meta, will send with `x-oss-meta-` prefix string
  1381. e.g.: `{ uid: 123, pid: 110 }`
  1382. - [callback] {Object} The callback parameter is composed of a JSON string encoded in Base64,detail [see](https://www.alibabacloud.com/help/doc-detail/31989.htm)<br>
  1383. - url {String} After a file is uploaded successfully, the OSS sends a callback request to this URL.
  1384. - [host] {String} The host header value for initiating callback requests.
  1385. - body {String} The value of the request body when a callback is initiated, for example, key=${key}&etag=${etag}&my_var=${x:my_var}.
  1386. - [contentType] {String} The Content-Type of the callback requests initiatiated, It supports application/x-www-form-urlencoded and application/json, and the former is the default value.
  1387. - [callbackSNI] {Boolean} Specifies whether OSS sends Server Name Indication (SNI) to the origin address specified by callbackUrl when a callback request is initiated from the client.
  1388. - [customValue] {Object} Custom parameters are a map of key-values<br>
  1389. e.g.:
  1390. ```js
  1391. var customValue = { var1: 'value1', var2: 'value2' };
  1392. ```
  1393. - [headers] {Object} extra headers, detail see [RFC 2616](http://www.w3.org/Protocols/rfc2616/rfc2616.html)
  1394. - 'Cache-Control' cache control for download, e.g.: `Cache-Control: public, no-cache`
  1395. - 'Content-Disposition' object name for download, e.g.: `Content-Disposition: somename`
  1396. - 'Content-Encoding' object content encoding for download, e.g.: `Content-Encoding: gzip`
  1397. - 'Expires' expires time for download, an absolute date and time. e.g.: `Tue, 08 Dec 2020 13:49:43 GMT`
  1398. Success will return the object information.
  1399. object:
  1400. - name {String} object name
  1401. - res {Object} response info, including
  1402. - status {Number} response status
  1403. - headers {Object} response headers
  1404. - size {Number} response size
  1405. - rt {Number} request total use time (ms)
  1406. example:
  1407. - Add an object through readstream
  1408. ```js
  1409. const filepath = '/home/ossdemo/demo.txt';
  1410. store.putStream('ossdemo/readstream.txt', fs.createReadStream(filepath)).then((result) => {
  1411. console.log(result);
  1412. });
  1413. // {
  1414. // name: 'ossdemo/readstream.txt',
  1415. // url: 'http://demo.oss-cn-hangzhou.aliyuncs.com/ossdemo/readstream.txt',
  1416. // res: {
  1417. // status: 200,
  1418. // headers: {
  1419. // date: 'Tue, 17 Feb 2015 13:28:17 GMT',
  1420. // 'content-length': '0',
  1421. // connection: 'close',
  1422. // etag: '"BF7A03DA01440845BC5D487B369BC168"',
  1423. // server: 'AliyunOSS',
  1424. // 'x-oss-request-id': '54E341F1707AA0275E829242'
  1425. // },
  1426. // size: 0,
  1427. // rt: 92
  1428. // }
  1429. // }
  1430. ```
  1431. ### .append(name, file[, options])
  1432. Append an object to the bucket, it's almost same as put, but it can add content to existing object rather than override it.
  1433. All parameters are same as put except for options.position
  1434. - name {String} object name store on OSS
  1435. - file {String|Buffer|ReadStream} object local path, content buffer or ReadStream content instance
  1436. - [options] {Object} optional parameters
  1437. - [position] {String} specify the position which is the content length of the latest object
  1438. - [timeout] {Number} the operation timeout
  1439. - [mime] {String} custom mime, will send with `Content-Type` entity header
  1440. - [meta] {Object} user meta, will send with `x-oss-meta-` prefix string
  1441. e.g.: `{ uid: 123, pid: 110 }`
  1442. - [headers] {Object} extra headers, detail see [RFC 2616](http://www.w3.org/Protocols/rfc2616/rfc2616.html)
  1443. - 'Cache-Control' cache control for download, e.g.: `Cache-Control: public, no-cache`
  1444. - 'Content-Disposition' object name for download, e.g.: `Content-Disposition: somename`
  1445. - 'Content-Encoding' object content encoding for download, e.g.: `Content-Encoding: gzip`
  1446. - 'Expires' expires time for download, an absolute date and time. e.g.: `Tue, 08 Dec 2020 13:49:43 GMT`
  1447. object:
  1448. - name {String} object name
  1449. - url {String} the url of oss
  1450. - res {Object} response info, including
  1451. - status {Number} response status
  1452. - headers {Object} response headers
  1453. - size {Number} response size
  1454. - rt {Number} request total use time (ms)
  1455. - nextAppendPosition {String} the next position(The browser needs to set cross domain and expose the x-oss-next-append-position header)
  1456. example:
  1457. ```js
  1458. let object = await store.append('ossdemo/buffer', Buffer.from('foo'));
  1459. // append content to the existing object
  1460. object = await store.append('ossdemo/buffer', Buffer.from('bar'), {
  1461. position: object.nextAppendPosition
  1462. });
  1463. ```
  1464. ### .getObjectUrl(name[, baseUrl])
  1465. Get the Object url.
  1466. If provide `baseUrl`, will use `baseUrl` instead the default `endpoint`.
  1467. e.g.:
  1468. ```js
  1469. const cdnUrl = store.getObjectUrl('foo/bar.jpg', 'https://mycdn.domian.com');
  1470. // cdnUrl should be `https://mycdn.domian.com/foo/bar.jpg`
  1471. ```
  1472. ### .generateObjectUrl(name[, baseUrl])
  1473. Get the Object url.
  1474. If provide `baseUrl`, will use `baseUrl` instead the default `bucket and endpoint `.
  1475. Suggest use generateObjectUrl instead of getObjectUrl.
  1476. e.g.:
  1477. ```js
  1478. const url = store.generateObjectUrl('foo/bar.jpg');
  1479. // cdnUrl should be `https://${bucketname}.${endpotint}foo/bar.jpg`
  1480. const cdnUrl = store.generateObjectUrl('foo/bar.jpg', 'https://mycdn.domian.com');
  1481. // cdnUrl should be `https://mycdn.domian.com/foo/bar.jpg`
  1482. ```
  1483. ### .head(name[, options])
  1484. Head an object and get the meta info.
  1485. parameters:
  1486. - name {String} object name store on OSS
  1487. - [options] {Object} optional parameters
  1488. - [timeout] {Number} the operation timeout
  1489. - [versionId] {String} the version id of history object
  1490. - [headers] {Object} extra headers, detail see [RFC 2616](http://www.w3.org/Protocols/rfc2616/rfc2616.html)
  1491. - 'If-Modified-Since' object modified after this time will return 200 and object meta,
  1492. otherwise return 304 not modified
  1493. - 'If-Unmodified-Since' object modified before this time will return 200 and object meta,
  1494. otherwise throw PreconditionFailedError
  1495. - 'If-Match' object etag equal this will return 200 and object meta,
  1496. otherwise throw PreconditionFailedError
  1497. - 'If-None-Match' object etag not equal this will return 200 and object meta,
  1498. otherwise return 304 not modified
  1499. Success will return the object's meta information.
  1500. object:
  1501. - status {Number} response status, maybe 200 or 304
  1502. - meta {Object} object user meta, if not set on `put()`, will return null.
  1503. If return status 304, meta will be null too
  1504. - res {Object} response info, including
  1505. - status {Number} response status
  1506. - headers {Object} response headers
  1507. - [x-oss-version-id] return in multiversion
  1508. - size {Number} response size
  1509. - rt {Number} request total use time (ms)
  1510. example:
  1511. - Head an exists object and get user meta
  1512. ```js
  1513. await this.store.put('ossdemo/head-meta', Buffer.from('foo'), {
  1514. meta: {
  1515. uid: 1,
  1516. path: 'foo/demo.txt'
  1517. }
  1518. });
  1519. const object = await this.store.head('ossdemo/head-meta');
  1520. console.log(object);
  1521. // {
  1522. // status: 200,
  1523. // meta: {
  1524. // uid: '1',
  1525. // path: 'foo/demo.txt'
  1526. // },
  1527. // res: { ... }
  1528. // }
  1529. ```
  1530. - Head a not exists object
  1531. ```js
  1532. const object = await this.store.head('ossdemo/head-meta');
  1533. // will throw NoSuchKeyError
  1534. ```
  1535. ### .getObjectMeta(name[, options])
  1536. Get an object meta info include ETag、Size、LastModified and so on, not return object content.
  1537. parameters:
  1538. - name {String} object name store on OSS
  1539. - [options] {Object} optional parameters
  1540. - [timeout] {Number} the operation timeout
  1541. - [versionId] {String} the version id of history object
  1542. Success will return the object's meta information.
  1543. object:
  1544. - status {Number} response status
  1545. - res {Object} response info, including
  1546. - headers {Object} response headers
  1547. example:
  1548. - Head an exists object and get object meta info
  1549. ```js
  1550. await this.store.put('ossdemo/object-meta', Buffer.from('foo'));
  1551. const object = await this.store.getObjectMeta('ossdemo/object-meta');
  1552. console.log(object);
  1553. // {
  1554. // status: 200,
  1555. // res: { ... }
  1556. // }
  1557. ```
  1558. ### .get(name[, file, options])
  1559. Get an object from the bucket.
  1560. parameters:
  1561. - name {String} object name store on OSS
  1562. - [file] {String|WriteStream|Object} file path or WriteStream instance to store the content
  1563. If `file` is null or ignore this parameter, function will return info contains `content` property.
  1564. If `file` is Object, it will be treated as options.
  1565. - [options] {Object} optional parameters
  1566. - [versionId] {String} the version id of history object
  1567. - [timeout] {Number} the operation timeout
  1568. - [process] {String} image process params, will send with `x-oss-process`
  1569. e.g.: `{process: 'image/resize,w_200'}`
  1570. - [responseCacheControl] {String} default `no-cache`, (only support Browser). response-cache-control, will response with HTTP Header `Cache-Control`
  1571. - [headers] {Object} extra headers, detail see [RFC 2616](http://www.w3.org/Protocols/rfc2616/rfc2616.html)
  1572. - 'Range' get specifying range bytes content, e.g.: `Range: bytes=0-9`
  1573. - 'If-Modified-Since' object modified after this time will return 200 and object meta,
  1574. otherwise return 304 not modified
  1575. - 'If-Unmodified-Since' object modified before this time will return 200 and object meta,
  1576. otherwise throw PreconditionFailedError
  1577. - 'If-Match' object etag equal this will return 200 and object meta,
  1578. otherwise throw PreconditionFailedError
  1579. - 'If-None-Match' object etag not equal this will return 200 and object meta,
  1580. otherwise return 304 not modified
  1581. Success will return the info contains response.
  1582. object:
  1583. - [content] {Buffer} file content buffer if `file` parameter is null or ignore
  1584. - res {Object} response info, including
  1585. - status {Number} response status
  1586. - headers {Object} response headers
  1587. - size {Number} response size
  1588. - rt {Number} request total use time (ms)
  1589. If object not exists, will throw NoSuchKeyError.
  1590. example:
  1591. - Get an exists object and store it to the local file
  1592. ```js
  1593. const filepath = '/home/ossdemo/demo.txt';
  1594. await store.get('ossdemo/demo.txt', filepath);
  1595. ```
  1596. \_ Store object to a writestream
  1597. ```js
  1598. await store.get('ossdemo/demo.txt', somestream);
  1599. ```
  1600. - Get an object content buffer
  1601. ```js
  1602. const result = await store.get('ossdemo/demo.txt');
  1603. console.log(Buffer.isBuffer(result.content));
  1604. ```
  1605. - Get a processed image and store it to the local file
  1606. ```js
  1607. const filepath = '/home/ossdemo/demo.png';
  1608. await store.get('ossdemo/demo.png', filepath, { process: 'image/resize,w_200' });
  1609. ```
  1610. - Get a not exists object
  1611. ```js
  1612. const filepath = '/home/ossdemo/demo.txt';
  1613. await store.get('ossdemo/not-exists-demo.txt', filepath);
  1614. // will throw NoSuchKeyError
  1615. ```
  1616. - Get a historic version object
  1617. ```js
  1618. const filepath = '/home/ossdemo/demo.txt';
  1619. const versionId = 'versionId string';
  1620. await store.get('ossdemo/not-exists-demo.txt', filepath, {
  1621. versionId
  1622. });
  1623. ```
  1624. - If `file` is Object, it will be treated as options.
  1625. ```js
  1626. const versionId = 'versionId string';
  1627. await store.get('ossdemo/not-exists-demo.txt', { versionId });
  1628. ```
  1629. ### .getStream(name[, options])
  1630. Get an object read stream.
  1631. parameters:
  1632. - name {String} object name store on OSS
  1633. - [options] {Object} optional parameters
  1634. - [timeout] {Number} the operation timeout
  1635. - [process] {String} image process params, will send with `x-oss-process`
  1636. - [headers] {Object} extra headers
  1637. - 'If-Modified-Since' object modified after this time will return 200 and object meta,
  1638. otherwise return 304 not modified
  1639. - 'If-Unmodified-Since' object modified before this time will return 200 and object meta,
  1640. otherwise throw PreconditionFailedError
  1641. - 'If-Match' object etag equal this will return 200 and object meta,
  1642. otherwise throw PreconditionFailedError
  1643. - 'If-None-Match' object etag not equal this will return 200 and object meta,
  1644. otherwise return 304 not modified
  1645. Success will return the stream instance and response info.
  1646. object:
  1647. - stream {ReadStream} readable stream instance. If response status is not `200`, stream will be `null`.
  1648. - res {Object} response info, including
  1649. - status {Number} response status
  1650. - headers {Object} response headers
  1651. - size {Number} response size
  1652. - rt {Number} request total use time (ms)
  1653. If object not exists, will throw NoSuchKeyError.
  1654. example:
  1655. - Get an exists object stream
  1656. ```js
  1657. const result = await store.getStream('ossdemo/demo.txt');
  1658. result.stream.pipe(fs.createWriteStream('some file.txt'));
  1659. ```
  1660. ### .delete(name[, options])
  1661. Delete an object from the bucket.
  1662. parameters:
  1663. - name {String} object name store on OSS
  1664. - [options] {Object} optional parameters
  1665. - [timeout] {Number} the operation timeout
  1666. - [versionId] {String} the version id of history object
  1667. Success will return the info contains response.
  1668. object:
  1669. - res {Object} response info, including
  1670. - status {Number} response status
  1671. - headers {Object} response headers
  1672. - size {Number} response size
  1673. - rt {Number} request total use time (ms)
  1674. If delete object not exists, will also delete success.
  1675. example:
  1676. - Delete an exists object
  1677. ```js
  1678. await store.delete('ossdemo/someobject');
  1679. ```
  1680. - Delete a not exists object
  1681. ```js
  1682. await store.delete('ossdemo/some-not-exists-object');
  1683. ```
  1684. - Delete a history object or deleteMarker
  1685. ```js
  1686. const versionId = 'versionId';
  1687. await store.delete('ossdemo/some-not-exists-object', { versionId });
  1688. ```
  1689. ### .copy(name, sourceName[, sourceBucket, options])
  1690. Copy an object from `sourceName` to `name`.
  1691. parameters:
  1692. - name {String} object name store on OSS
  1693. - sourceName {String} source object name
  1694. - [sourceBucket] {String} source Bucket. if doesn't exist,`sourceBucket` is same bucket.
  1695. - [options] {Object} optional parameters
  1696. - [versionId] {String} the version id of history object
  1697. - [timeout] {Number} the operation timeout
  1698. - [meta] {Object} user meta, will send with `x-oss-meta-` prefix string
  1699. e.g.: `{ uid: 123, pid: 110 }`
  1700. If the `meta` set, will override the source object meta.
  1701. - [headers] {Object} extra headers
  1702. - 'If-Match' do copy if source object etag equal this,
  1703. otherwise throw PreconditionFailedError
  1704. - 'If-None-Match' do copy if source object etag not equal this,
  1705. otherwise throw PreconditionFailedError
  1706. - 'If-Modified-Since' do copy if source object modified after this time,
  1707. otherwise throw PreconditionFailedError
  1708. - 'If-Unmodified-Since' do copy if source object modified before this time,
  1709. otherwise throw PreconditionFailedError
  1710. - See more: [CopyObject](https://help.aliyun.com/document_detail/31979.html?#title-tzy-vxc-ncx)
  1711. Success will return the copy result in `data` property.
  1712. object:
  1713. - data {Object} copy result
  1714. - lastModified {String} object last modified GMT string
  1715. - etag {String} object etag contains `"`, e.g.: `"5B3C1A2E053D763E1B002CC607C5A0FE"`
  1716. - res {Object} response info, including
  1717. - status {Number} response status
  1718. - headers {Object} response headers
  1719. - size {Number} response size
  1720. - rt {Number} request total use time (ms)
  1721. If source object not exists, will throw NoSuchKeyError.
  1722. example:
  1723. - Copy same bucket object
  1724. ```js
  1725. store.copy('newName', 'oldName').then(result => {
  1726. console.log(result);
  1727. });
  1728. ```
  1729. - Copy other bucket object
  1730. ```js
  1731. store.copy('logo.png', 'logo.png', 'other-bucket').then(result => {
  1732. console.log(result);
  1733. });
  1734. ```
  1735. - Copy historic object
  1736. ```js
  1737. const versionId = 'your verisonId';
  1738. store.copy('logo.png', 'logo.png', 'other-bucket', { versionId }).then(result => {
  1739. console.log(result);
  1740. });
  1741. ```
  1742. ### .putMeta(name, meta[, options])
  1743. Set an exists object meta.
  1744. parameters:
  1745. - name {String} object name store on OSS
  1746. - meta {Object} user meta, will send with `x-oss-meta-` prefix string
  1747. e.g.: `{ uid: 123, pid: 110 }`
  1748. If `meta: null`, will clean up the exists meta
  1749. - [options] {Object} optional parameters
  1750. - [timeout] {Number} the operation timeout
  1751. Success will return the putMeta result in `data` property.
  1752. - data {Object} copy result
  1753. - lastModified {String} object last modified GMT date, e.g.: `2015-02-19T08:39:44.000Z`
  1754. - etag {String} object etag contains `"`, e.g.: `"5B3C1A2E053D763E1B002CC607C5A0FE"`
  1755. - res {Object} response info, including
  1756. - status {Number} response status
  1757. - headers {Object} response headers
  1758. - size {Number} response size
  1759. - rt {Number} request total use time (ms)
  1760. If object not exists, will throw NoSuchKeyError.
  1761. example:
  1762. - Update exists object meta
  1763. ```js
  1764. const result = await store.putMeta('ossdemo.txt', {
  1765. uid: 1,
  1766. pid: 'p123'
  1767. });
  1768. console.log(result);
  1769. ```
  1770. - Clean up object meta
  1771. ```js
  1772. await store.putMeta('ossdemo.txt', null);
  1773. ```
  1774. ### .deleteMulti(names[, options])
  1775. Delete multi objects in one request.
  1776. parameters:
  1777. - names {Array<Object>} object names, max 1000 objects in once.
  1778. - key {String} object name
  1779. - [versionId] {String} the version id of history object or deleteMarker
  1780. - [options] {Object} optional parameters
  1781. - [quiet] {Boolean} quiet mode or verbose mode, default is `false`, verbose mode
  1782. quiet mode: if all objects delete succes, return emtpy response.
  1783. otherwise return delete error object results.
  1784. verbose mode: return all object delete results.
  1785. - [timeout] {Number} the operation timeout
  1786. Success will return delete success objects in `deleted` property.
  1787. - [deleted] {Array<Object>} deleted object or deleteMarker info list
  1788. - [Key] {String} object name
  1789. - [VersionId] {String} object versionId
  1790. - [DeleteMarker] {String} generate or delete marker
  1791. - [DeleteMarkerVersionId] {String} marker versionId
  1792. - res {Object} response info, including
  1793. - status {Number} response status
  1794. - headers {Object} response headers
  1795. - size {Number} response size
  1796. - rt {Number} request total use time (ms)
  1797. example:
  1798. - Delete multi objects in quiet mode
  1799. ```js
  1800. const result = await store.deleteMulti(['obj1', 'obj2', 'obj3'], {
  1801. quiet: true
  1802. });
  1803. ```
  1804. - Delete multi objects in verbose mode
  1805. ```js
  1806. const result = await store.deleteMulti(['obj1', 'obj2', 'obj3']);
  1807. ```
  1808. - Delete multi objects in multiversion
  1809. ```js
  1810. const obj1 = {
  1811. key: 'key1',
  1812. versionId: 'versionId1'
  1813. };
  1814. const obj2 = {
  1815. key: 'key2',
  1816. versionId: 'versionId2'
  1817. };
  1818. const result = await store.deleteMulti([obj1, obj2]);
  1819. ```
  1820. ### .list(query[, options])
  1821. List objects in the bucket.
  1822. parameters:
  1823. - [query] {Object} query parameters, default is `null`
  1824. - [prefix] {String} search object using `prefix` key
  1825. - [marker] {String} search start from `marker`, including `marker` key
  1826. - [delimiter] {String} delimiter search scope
  1827. e.g. `/` only search current dir, not including subdir
  1828. - [max-keys] {String|Number} max objects, default is `100`, limit to `1000`
  1829. - [options] {Object} optional parameters
  1830. - [timeout] {Number} the operation timeout
  1831. Success will return objects list on `objects` properties.
  1832. - objects {Array<ObjectMeta>} object meta info list
  1833. Each `ObjectMeta` will contains blow properties:
  1834. - name {String} object name on oss
  1835. - lastModified {String} object last modified GMT date, e.g.: `2015-02-19T08:39:44.000Z`
  1836. - etag {String} object etag contains `"`, e.g.: `"5B3C1A2E053D763E1B002CC607C5A0FE"`
  1837. - type {String} object type, e.g.: `Normal`
  1838. - size {Number} object size, e.g.: `344606`
  1839. - storageClass {String} storage class type, e.g.: `Standard`
  1840. - owner {Object} object owner, including `id` and `displayName`
  1841. - restoreInfo {Object|undefined} The restoration status of the object
  1842. - ongoingRequest {Boolean} Whether the restoration is ongoing
  1843. - expireDate {Date|undefined} The time before which the restored object can be read
  1844. - prefixes {Array<String>} prefix list
  1845. - isTruncated {Boolean} truncate or not
  1846. - nextMarker {String} next marker string
  1847. - res {Object} response info, including
  1848. - status {Number} response status
  1849. - headers {Object} response headers
  1850. - size {Number} response size
  1851. - rt {Number} request total use time (ms)
  1852. example:
  1853. - List top 10 objects
  1854. ```js
  1855. const result = await store.list();
  1856. console.log(result.objects);
  1857. ```
  1858. - List `fun/` dir including subdirs objects
  1859. ```js
  1860. const result = await store.list({
  1861. prefix: 'fun/'
  1862. });
  1863. console.log(result.objects);
  1864. ```
  1865. - List `fun/` dir objects, not including subdirs
  1866. ```js
  1867. const result = await store.list({
  1868. prefix: 'fun/',
  1869. delimiter: '/'
  1870. });
  1871. console.log(result.objects);
  1872. ```
  1873. ### .listV2(query[, options])
  1874. List objects in the bucket.(recommended)
  1875. parameters:
  1876. - [query] {Object} query parameters, default is `null`
  1877. - [prefix] {String} search object using `prefix` key
  1878. - [continuation-token] (continuationToken) {String} search start from `continuationToken`, including `continuationToken` key
  1879. - [delimiter] {String} delimiter search scope
  1880. e.g. `/` only search current dir, not including subdir
  1881. - [max-keys] {String|Number} max objects, default is `100`, limit to `1000`
  1882. - [start-after] {String} specifies the Start-after value from which to start the list. The names of objects are returned in alphabetical order.
  1883. - [fetch-owner] {Boolean} specifies whether to include the owner information in the response.
  1884. - [options] {Object} optional parameters
  1885. - [timeout] {Number} the operation timeout
  1886. Success will return objects list on `objects` properties.
  1887. - objects {Array<ObjectMeta>} object meta info list
  1888. Each `ObjectMeta` will contains blow properties:
  1889. - name {String} object name on oss
  1890. - url {String} resource url
  1891. - lastModified {String} object last modified GMT date, e.g.: `2015-02-19T08:39:44.000Z`
  1892. - etag {String} object etag contains `"`, e.g.: `"5B3C1A2E053D763E1B002CC607C5A0FE"`
  1893. - type {String} object type, e.g.: `Normal`
  1894. - size {Number} object size, e.g.: `344606`
  1895. - storageClass {String} storage class type, e.g.: `Standard`
  1896. - owner {Object|null} object owner, including `id` and `displayName`
  1897. - restoreInfo {Object|undefined} The restoration status of the object
  1898. - ongoingRequest {Boolean} Whether the restoration is ongoing
  1899. - expireDate {Date|undefined} The time before which the restored object can be read
  1900. - prefixes {Array<String>} prefix list
  1901. - isTruncated {Boolean} truncate or not
  1902. - nextContinuationToken {String} next continuation-token string
  1903. - keyCount {Number} The number of keys returned for this request. If Delimiter is specified, KeyCount is the sum of the elements in Key and CommonPrefixes.
  1904. - res {Object} response info, including
  1905. - status {Number} response status
  1906. - headers {Object} response headers
  1907. - size {Number} response size
  1908. - rt {Number} request total use time (ms)
  1909. - List top 10 objects
  1910. ```js
  1911. const result = await store.listV2({
  1912. 'max-keys': 10
  1913. });
  1914. console.log(result.objects);
  1915. ```
  1916. - List `fun/` dir including subdirs objects
  1917. ```js
  1918. const result = await store.listV2({
  1919. prefix: 'fun/'
  1920. });
  1921. console.log(result.objects);
  1922. ```
  1923. - List `fun/` dir objects, not including subdirs
  1924. ```js
  1925. const result = await store.listV2({
  1926. prefix: 'fun/',
  1927. delimiter: '/'
  1928. });
  1929. console.log(result.objects);
  1930. ```
  1931. - List `a/` dir objects, after `a/b` and not include `a/b`
  1932. ```js
  1933. const result = await store.listV2({
  1934. delimiter: '/',
  1935. prefix: 'a/',
  1936. 'start-after': 'a/b'
  1937. });
  1938. console.log(result.objects);
  1939. ```
  1940. ### .getBucketVersions(query[, options])
  1941. List the version information of all objects in the bucket, including the delete marker (Delete Marker).
  1942. parameters:
  1943. - [query] {Object} query parameters, default is `null`
  1944. - [prefix] {String} search object using `prefix` key
  1945. - [versionIdMarker] {String} set the result to return from the version ID marker of the key marker object and sort by the versions
  1946. - [keyMarker] {String} search start from `keyMarker`, including `keyMarker` key
  1947. - [encodingType] {String} specifies that the returned content is encoded, and specifies the type of encoding
  1948. - [delimiter] {String} delimiter search scope
  1949. e.g. `/` only search current dir, not including subdir
  1950. - [maxKeys] {String|Number} max objects, default is `100`, limit to `1000`
  1951. - [options] {Object} optional parameters
  1952. - [timeout] {Number} the operation timeout
  1953. Success will return objects list on `objects` properties.
  1954. - objects {Array<ObjectMeta>} object meta info list
  1955. Each `ObjectMeta` will contains blow properties:
  1956. - name {String} object name on oss
  1957. - lastModified {String} object last modified GMT date, e.g.: `2015-02-19T08:39:44.000Z`
  1958. - etag {String} object etag contains `"`, e.g.: `"5B3C1A2E053D763E1B002CC607C5A0FE"`
  1959. - type {String} object type, e.g.: `Normal`
  1960. - size {Number} object size, e.g.: `344606`
  1961. - isLatest {Boolean}
  1962. - versionId {String} object versionId
  1963. - storageClass {String} storage class type, e.g.: `Standard`
  1964. - owner {Object} object owner, including `id` and `displayName`
  1965. - restoreInfo {Object|undefined} The restoration status of the object
  1966. - ongoingRequest {Boolean} Whether the restoration is ongoing
  1967. - expireDate {Date|undefined} The time before which the restored object can be read
  1968. - deleteMarker {Array<ObjectDeleteMarker>} object delete marker info list
  1969. Each `ObjectDeleteMarker`
  1970. - name {String} object name on oss
  1971. - lastModified {String} object last modified GMT date, e.g.: `2015-02-19T08:39:44.000Z`
  1972. - versionId {String} object versionId
  1973. - isTruncated {Boolean} truncate or not
  1974. - nextKeyMarker (nextMarker) {String} next marker string
  1975. - nextVersionIdMarker (NextVersionIdMarker) {String} next version ID marker string
  1976. - res {Object} response info, including
  1977. - status {Number} response status
  1978. - headers {Object} response headers
  1979. - size {Number} response size
  1980. - rt {Number} request total use time (ms)
  1981. example:
  1982. - View all versions of objects and deleteMarker of bucket
  1983. ```js
  1984. const result = await store.getBucketVersions();
  1985. console.log(result.objects);
  1986. console.log(result.deleteMarker);
  1987. ```
  1988. - List from key-marker
  1989. ```js
  1990. const result = await store.getBucketVersions({
  1991. keyMarker: 'keyMarker'
  1992. });
  1993. console.log(result.objects);
  1994. ```
  1995. - List from the version-id-marker of key-marker
  1996. ```js
  1997. const result = await store.getBucketVersions({
  1998. versionIdMarker: 'versionIdMarker',
  1999. keyMarker: 'keyMarker'
  2000. });
  2001. console.log(result.objects);
  2002. console.log(result.deleteMarker);
  2003. ```
  2004. ### .signatureUrl(name[, options, strictObjectNameValidation])
  2005. Create a signature url for download or upload object. When you put object with signatureUrl ,you need to pass `Content-Type`.Please look at the example.
  2006. parameters:
  2007. - name {String} object name store on OSS
  2008. - [options] {Object} optional parameters
  2009. - [expires] {Number} after expires seconds, the url will become invalid, default is `1800`
  2010. - [method] {String} the HTTP method, default is 'GET'
  2011. - [Content-Type] {String} set the request content type
  2012. - [process] {String} image process params, will send with `x-oss-process`
  2013. e.g.: `{process: 'image/resize,w_200'}`
  2014. - [trafficLimit] {Number} traffic limit, range: `819200`~`838860800`.
  2015. - [subResource] {Object} additional signature parameters in url.
  2016. - [response] {Object} set the response headers for download
  2017. - [content-type] {String} set the response content type
  2018. - [content-disposition] {String} set the response content disposition
  2019. - [cache-control] {String} set the response cache control
  2020. - See more: <https://help.aliyun.com/document_detail/31980.html>
  2021. - [callback] {Object} set the callback for the operation
  2022. - url {String} set the url for callback
  2023. - [host] {String} set the host for callback
  2024. - body {String} set the body for callback
  2025. - [contentType] {String} set the type for body
  2026. - [callbackSNI] {Boolean} Specifies whether OSS sends Server Name Indication (SNI) to the origin address specified by callbackUrl when a callback request is initiated from the client
  2027. - [customValue] {Object} set the custom value for callback,eg. {var1: value1,var2:value2}
  2028. - [strictObjectNameValidation] {boolean} the flag of verifying object name strictly, default is true
  2029. Success will return signature url.
  2030. example:
  2031. - Get signature url for object
  2032. ```js
  2033. const url = store.signatureUrl('ossdemo.txt');
  2034. console.log(url);
  2035. // --------------------------------------------------
  2036. const url = store.signatureUrl('ossdemo.txt', {
  2037. expires: 3600,
  2038. method: 'PUT'
  2039. });
  2040. console.log(url);
  2041. // put object with signatureUrl
  2042. // -------------------------------------------------
  2043. const url = store.signatureUrl('ossdemo.txt', {
  2044. expires: 3600,
  2045. method: 'PUT',
  2046. 'Content-Type': 'text/plain; charset=UTF-8'
  2047. });
  2048. console.log(url);
  2049. // --------------------------------------------------
  2050. const url = store.signatureUrl(
  2051. 'ossdemo.txt',
  2052. {
  2053. expires: 3600,
  2054. response: {
  2055. 'content-type': 'text/custom',
  2056. 'content-disposition': 'attachment'
  2057. }
  2058. },
  2059. false
  2060. );
  2061. console.log(url);
  2062. // put operation
  2063. ```
  2064. - Get a signature url for a processed image
  2065. ```js
  2066. const url = store.signatureUrl('ossdemo.png', {
  2067. process: 'image/resize,w_200'
  2068. });
  2069. console.log(url);
  2070. // --------------------------------------------------
  2071. const url = store.signatureUrl('ossdemo.png', {
  2072. expires: 3600,
  2073. process: 'image/resize,w_200'
  2074. });
  2075. console.log(url);
  2076. ```
  2077. ### .asyncSignatureUrl(name[, options, strictObjectNameValidation])
  2078. Basically the same as signatureUrl, if refreshSTSToken is configured asyncSignatureUrl will refresh stsToken
  2079. parameters:
  2080. - name {String} object name store on OSS
  2081. - [options] {Object} optional parameters
  2082. - [expires] {Number} after expires seconds, the url will become invalid, default is `1800`
  2083. - [method] {String} the HTTP method, default is 'GET'
  2084. - [Content-Type] {String} set the request content type
  2085. - [process] {String} image process params, will send with `x-oss-process`
  2086. e.g.: `{process: 'image/resize,w_200'}`
  2087. - [trafficLimit] {Number} traffic limit, range: `819200`~`838860800`.
  2088. - [subResource] {Object} additional signature parameters in url.
  2089. - [response] {Object} set the response headers for download
  2090. - [content-type] {String} set the response content type
  2091. - [content-disposition] {String} set the response content disposition
  2092. - [cache-control] {String} set the response cache control
  2093. - See more: <https://help.aliyun.com/document_detail/31980.html>
  2094. - [callback] {Object} set the callback for the operation
  2095. - url {String} set the url for callback
  2096. - [host] {String} set the host for callback
  2097. - body {String} set the body for callback
  2098. - [contentType] {String} set the type for body
  2099. - [callbackSNI] {Boolean} Specifies whether OSS sends Server Name Indication (SNI) to the origin address specified by callbackUrl when a callback request is initiated from the client
  2100. - [customValue] {Object} set the custom value for callback,eg. {var1: value1,var2:value2}
  2101. - [strictObjectNameValidation] {boolean} the flag of verifying object name strictly, default is true
  2102. Success will return signature url.
  2103. example:
  2104. - Get signature url for object
  2105. ```js
  2106. const url = await store.asyncSignatureUrl('ossdemo.txt');
  2107. console.log(url);
  2108. // --------------------------------------------------
  2109. const url = await store.asyncSignatureUrl('ossdemo.txt', {
  2110. expires: 3600,
  2111. method: 'PUT'
  2112. });
  2113. console.log(url);
  2114. // put object with signatureUrl
  2115. // -------------------------------------------------
  2116. const url = await store.asyncSignatureUrl('ossdemo.txt', {
  2117. expires: 3600,
  2118. method: 'PUT',
  2119. 'Content-Type': 'text/plain; charset=UTF-8'
  2120. });
  2121. console.log(url);
  2122. // --------------------------------------------------
  2123. const url = await store.asyncSignatureUrl(
  2124. 'ossdemo.txt',
  2125. {
  2126. expires: 3600,
  2127. response: {
  2128. 'content-type': 'text/custom',
  2129. 'content-disposition': 'attachment'
  2130. }
  2131. },
  2132. false
  2133. );
  2134. console.log(url);
  2135. // put operation
  2136. ```
  2137. - Get a signature url for a processed image
  2138. ```js
  2139. const url = await store.asyncSignatureUrl('ossdemo.png', {
  2140. process: 'image/resize,w_200'
  2141. });
  2142. console.log(url);
  2143. // --------------------------------------------------
  2144. const url = await store.asyncSignatureUrl('ossdemo.png', {
  2145. expires: 3600,
  2146. process: 'image/resize,w_200'
  2147. });
  2148. console.log(url);
  2149. ```
  2150. ### .signatureUrlV4(method, expires[, request, objectName, additionalHeaders])
  2151. Generate a signed URL for V4 of an OSS resource and share the URL to allow authorized third-party users to access the resource.
  2152. parameters:
  2153. - method {string} the HTTP method
  2154. - expires {number} the signed URL will expire after the set number of seconds
  2155. - [request] {Object} optional request parameters
  2156. - [headers] {Object} headers of http requests, please make sure these request headers are set during the actual request
  2157. - [queries] {Object} queries of the signed URL, please ensure that if the query only has key, the value is set to null
  2158. - [objectName] {string} object name
  2159. - [additionalHeaders] {string[]} the keys of the request headers that need to be calculated into the V4 signature, please ensure that these additional headers are included in the request headers
  2160. Success will return signature url.
  2161. example:
  2162. ```js
  2163. // GetObject
  2164. const getObjectUrl = await store.signatureUrlV4('GET', 60, undefined, 'your obejct name');
  2165. console.log(getObjectUrl);
  2166. // --------------------------------------------------
  2167. const getObjectUrl = await store.signatureUrlV4(
  2168. 'GET',
  2169. 60,
  2170. {
  2171. headers: {
  2172. 'Cache-Control': 'no-cache'
  2173. },
  2174. queries: {
  2175. versionId: 'version ID of your object'
  2176. }
  2177. },
  2178. 'your obejct name',
  2179. ['Cache-Control']
  2180. );
  2181. console.log(getObjectUrl);
  2182. // -------------------------------------------------
  2183. // PutObject
  2184. const putObejctUrl = await store.signatureUrlV4('PUT', 60, undefined, 'your obejct name');
  2185. console.log(putObejctUrl);
  2186. // --------------------------------------------------
  2187. const putObejctUrl = await store.signatureUrlV4(
  2188. 'PUT',
  2189. 60,
  2190. {
  2191. headers: {
  2192. 'Content-Type': 'text/plain',
  2193. 'Content-MD5': 'xxx',
  2194. 'Content-Length': 1
  2195. }
  2196. },
  2197. 'your obejct name',
  2198. ['Content-Length']
  2199. );
  2200. console.log(putObejctUrl);
  2201. ```
  2202. ### .putACL(name, acl[, options])
  2203. Set object's ACL.
  2204. parameters:
  2205. - name {String} object name
  2206. - acl {String} acl (private/public-read/public-read-write)
  2207. - [options] {Object} optional parameters
  2208. - [timeout] {Number} the operation timeout
  2209. - [versionId] {String} the version id of history object
  2210. Success will return:
  2211. - res {Object} response info, including
  2212. - status {Number} response status
  2213. - headers {Object} response headers
  2214. - size {Number} response size
  2215. - rt {Number} request total use time (ms)
  2216. example:
  2217. - Set an object's ACL
  2218. ```js
  2219. await store.putACL('ossdemo.txt', 'public-read');
  2220. ```
  2221. - Set an history object's ACL
  2222. ```js
  2223. const versionId = 'object versionId';
  2224. await store.putACL('ossdemo.txt', 'public-read', {
  2225. versionId
  2226. });
  2227. ```
  2228. ### .getACL(name[, options])
  2229. Get object's ACL.
  2230. parameters:
  2231. - name {String} object name
  2232. - [options] {Object} optional parameters
  2233. - [timeout] {Number} the operation timeout
  2234. - [versionId] {String} the version id of history object
  2235. Success will return:
  2236. - acl {String} acl settiongs string
  2237. - res {Object} response info, including
  2238. - status {Number} response status
  2239. - headers {Object} response headers
  2240. - size {Number} response size
  2241. - rt {Number} request total use time (ms)
  2242. example:
  2243. - Get an object's ACL
  2244. ```js
  2245. const result = await store.getACL('ossdemo.txt');
  2246. console.log(result.acl);
  2247. ```
  2248. - Get an history object's ACL
  2249. ```js
  2250. const versionId = 'object versionId';
  2251. const result = await store.getACL('ossdemo.txt', { versionId });
  2252. console.log(result.acl);
  2253. ```
  2254. ### .restore(name[, options])
  2255. Restore Object.
  2256. parameters:
  2257. - name {String} object name
  2258. - [options] {Object} optional parameters
  2259. - [timeout] {Number} the operation timeout
  2260. - [versionId] {String} the version id of history object
  2261. - [type] {String} the default type is Archive
  2262. - [Days] {number} The duration within which the object remains in the restored state. The default value is 2.
  2263. - [JobParameters] {string} The container that stores the restoration priority. This parameter is valid only when you restore Cold Archive or Deep Cold Archive objects. The default value is Standard.
  2264. Success will return:
  2265. - res {Object} response info, including
  2266. - status {Number} response status
  2267. - headers {Object} response headers
  2268. - size {Number} response size
  2269. - rt {Number} request total use time (ms)
  2270. example:
  2271. - Restore an Archive object
  2272. ```js
  2273. const result = await store.restore('ossdemo.txt');
  2274. console.log(result.status);
  2275. ```
  2276. - Restore a Cold Archive object
  2277. ```js
  2278. const result = await store.restore('ossdemo.txt', { type: 'ColdArchive' });
  2279. console.log(result.status);
  2280. ```
  2281. - Restore a Cold Archive object with Days
  2282. ```js
  2283. const result = await store.restore('ossdemo.txt', { type: 'ColdArchive', Days: 2 });
  2284. console.log(result.status);
  2285. ```
  2286. - Restore a Cold Archive object with Days and JobParameters
  2287. ```js
  2288. const result = await store.restore('ossdemo.txt', { type: 'ColdArchive', Days: 2, JobParameters: 'Standard' });
  2289. console.log(result.status);
  2290. ```
  2291. - Restore a Deep Cold Archive object
  2292. ```js
  2293. const result = await store.restore('ossdemo.txt', { type: 'DeepColdArchive' });
  2294. console.log(result.status);
  2295. ```
  2296. - Restore a Deep Cold Archive object with Days
  2297. ```js
  2298. const result = await store.restore('ossdemo.txt', { type: 'DeepColdArchive', Days: 2 });
  2299. console.log(result.status);
  2300. ```
  2301. - Restore a Deep Cold Archive object with Days and JobParameters
  2302. ```js
  2303. const result = await store.restore('ossdemo.txt', { type: 'DeepColdArchive', Days: 2, JobParameters: 'Standard' });
  2304. console.log(result.status);
  2305. ```
  2306. - Restore an history object
  2307. ```js
  2308. const versionId = 'object versionId';
  2309. const result = await store.restore('ossdemo.txt', { versionId });
  2310. console.log(result.status);
  2311. ```
  2312. ### .putSymlink(name, targetName[, options])
  2313. PutSymlink
  2314. parameters:
  2315. - name {String} object name
  2316. - targetName {String} target object name
  2317. - [options] {Object} optional parameters
  2318. - [storageClass] {String} the storage type include (Standard,IA,Archive)
  2319. - [meta] {Object} user meta, will send with `x-oss-meta-` prefix string
  2320. - [headers] {Object} extra headers, detail see [PutSymlink](https://help.aliyun.com/document_detail/45126.html#title-x71-l2b-7i8)
  2321. - res {Object} response info, including
  2322. - status {Number} response status
  2323. - headers {Object} response headers
  2324. - size {Number} response size
  2325. - rt {Number} request total use time (ms)
  2326. example:
  2327. ```js
  2328. const options = {
  2329. storageClass: 'IA',
  2330. meta: {
  2331. uid: '1',
  2332. slus: 'test.html'
  2333. }
  2334. };
  2335. const result = await store.putSymlink('ossdemo.txt', 'targetName', options);
  2336. console.log(result.res);
  2337. ```
  2338. putSymlink multiversion
  2339. ```js
  2340. const options = {
  2341. storageClass: 'IA',
  2342. meta: {
  2343. uid: '1',
  2344. slus: 'test.html'
  2345. }
  2346. };
  2347. const result = await store.putSymlink('ossdemo.txt', 'targetName', options);
  2348. console.log(result.res.headers['x-oss-version-id']);
  2349. ```
  2350. ### .getSymlink(name[, options])
  2351. GetSymlink
  2352. parameters:
  2353. - name {String} object name
  2354. - [options] {Object} optional parameters
  2355. - [versionId] {String} the version id of history object
  2356. Success will return
  2357. - targetName {String} target object name
  2358. - res {Object} response info, including
  2359. - status {Number} response status
  2360. - headers {Object} response headers
  2361. - size {Number} response size
  2362. - rt {Number} request total use time (ms)
  2363. example:
  2364. ```js
  2365. const result = await store.getSymlink('ossdemo.txt');
  2366. console.log(result.targetName);
  2367. ```
  2368. for history object
  2369. ```js
  2370. const versionId = 'object versionId';
  2371. const result = await store.getSymlink('ossdemo.txt', { versionId });
  2372. console.log(result.targetName);
  2373. ```
  2374. ### .initMultipartUpload(name[, options])
  2375. Before transmitting data in the Multipart Upload mode,
  2376. you must call the Initiate Multipart Upload interface to notify the OSS to initiate a Multipart Upload event.
  2377. The Initiate Multipart Upload interface returns a globally unique Upload ID created by the OSS server to identify this Multipart Upload event.
  2378. parameters:
  2379. - name {String} object name
  2380. - [options] {Object} optional parameters
  2381. - [timeout] {Number} the operation timeout
  2382. - [mime] Mime file type e.g.: application/octet-stream
  2383. - [meta] {Object} user meta, will send with `x-oss-meta-` prefix string
  2384. - [headers] {Object} extra headers
  2385. - 'Cache-Control' cache control for download, e.g.: `Cache-Control: public, no-cache`
  2386. - 'Content-Disposition' object name for download, e.g.: `Content-Disposition: somename`
  2387. - 'Content-Encoding' object content encoding for download, e.g.: `Content-Encoding: gzip`
  2388. - 'Expires' expires time for download, an absolute date and time. e.g.: `Tue, 08 Dec 2020 13:49:43 GMT`
  2389. - [x-oss-server-side-encryption]
  2390. Specify the server-side encryption algorithm used to upload each part of this object,Type: string, Valid value: AES256 `x-oss-server-side-encryption: AES256`<br>
  2391. if use in browser you should be set cors expose header x-oss-server-side-encryption
  2392. - See more: [InitiateMultipartUpload](https://help.aliyun.com/document_detail/31992.html?#title-wh0-a2h-rur)
  2393. Success will return:
  2394. - res {Object} response info, including
  2395. - status {Number} response status
  2396. - headers {Object} response headers
  2397. - [x-oss-server-side-encryption] if set request header x-oss-server-side-encryption, will return
  2398. - size {Number} response size
  2399. - rt {Number} request total use time (ms)
  2400. - bucket {String} bucket name
  2401. - name {String} object name store on OSS
  2402. - uploadId {String} upload id, use for uploadPart, completeMultipart
  2403. example:
  2404. ```js
  2405. const result = await store.initMultipartUpload('object');
  2406. console.log(result);
  2407. ```
  2408. ### .uploadPart(name, uploadId, partNo, file, start, end[, options])
  2409. After initiating a Multipart Upload event, you can upload data in parts based on the specified object name and Upload ID.
  2410. parameters:
  2411. - name {String} object name
  2412. - uploadId {String} get by initMultipartUpload api
  2413. - partNo {Number} range is 1-10000, If this range is exceeded, OSS returns the InvalidArgument's error code.
  2414. - file {File|String} is File or FileName, the whole file<br>
  2415. Multipart Upload requires that the size of any Part other than the last Part is greater than 100KB. <br>
  2416. In Node you can use File or FileName, but in browser you only can use File.
  2417. - start {Number} part start bytes e.g: 102400
  2418. - end {Number} part end bytes e.g: 204800
  2419. - [options] {Object} optional parameters
  2420. - [timeout] {Number} the operation timeout
  2421. Success will return:
  2422. - res {Object} response info, including
  2423. - status {Number} response status
  2424. - headers {Object} response headers
  2425. - size {Number} response size
  2426. - rt {Number} request total use time (ms)
  2427. - name {String} object name store on OSS
  2428. - etag {String} object etag contains ", e.g.: "5B3C1A2E053D763E1B002CC607C5A0FE"
  2429. example:
  2430. ```js
  2431. const name = 'object';
  2432. const result = await store.initMultipartUpload(name);
  2433. const uploadId = result.uploadId;
  2434. const file; //the data you want to upload, is a File or FileName(only in node)
  2435. //if file part is 10
  2436. const partSize = 100 * 1024;
  2437. const fileSize = 10 * partSize;//you need to calculate
  2438. const dones = [];
  2439. for (let i = 1; i <= 10; i++) {
  2440. const start = partSize * (i -1);
  2441. const end = Math.min(start + partSize, fileSize);
  2442. const part = await store.uploadPart(name, uploadId, i, file, start, end);
  2443. dones.push({
  2444. number: i,
  2445. etag: part.etag
  2446. });
  2447. console.log(part);
  2448. }
  2449. //end need to call completeMultipartUpload api
  2450. ```
  2451. ### .uploadPartCopy(name, uploadId, partNo, range, sourceData[, options])
  2452. Using Upload Part Copy, you can copy data from an existing object and upload a part of the data.
  2453. When copying a file larger than 1 GB, you must use the Upload Part Copy method. If you want to copy a file smaller than 1 GB, see Copy Object.
  2454. parameters:
  2455. - name {String} object name
  2456. - uploadId {String} get by initMultipartUpload api
  2457. - partNo {Number} range is 1-10000, If this range is exceeded, OSS returns the InvalidArgument's error code.
  2458. - range {String} Multipart Upload requires that the size of any Part other than the last Part is greater than 100KB, range value like `0-102400`
  2459. - sourceData {Object}
  2460. - sourceKey {String} the source object name
  2461. - sourceBucketName {String} the source bucket name
  2462. - [options] {Object} optional parameters
  2463. - [timeout] {Number} the operation timeout
  2464. - [versionId] {String} the version id of history object
  2465. - [headers] {Object} The following request header is used for the source objects specified by x-oss-copy-source.
  2466. - [x-oss-copy-source-if-match] default none<br>
  2467. If the ETAG value of the source object is equal to the ETAG value provided by the user, the system performs the Copy Object operation; otherwise, the system returns the 412 Precondition Failed message.
  2468. - [x-oss-copy-source-if-none-match] default none<br>
  2469. If the source object has not been modified since the time specified by the user, the system performs the Copy Object operation; otherwise, the system returns the 412 Precondition Failed message.
  2470. - [x-oss-copy-source-if-unmodified-since] default none<br>
  2471. If the time specified by the received parameter is the same as or later than the modification time of the file, the system transfers the file normally, and returns 200 OK; otherwise, the system returns 412 Precondition Failed.
  2472. - [x-oss-copy-source-if-modified-since] default none<br>
  2473. If the source object has been modified since the time specified by the user, the system performs the Copy Object operation; otherwise, the system returns the 412 Precondition Failed message.
  2474. Success will return:
  2475. - res {Object} response info, including
  2476. - status {Number} response status
  2477. - headers {Object} response headers
  2478. - size {Number} response size
  2479. - rt {Number} request total use time (ms)
  2480. - name {String} object name store on OSS
  2481. - etag {String} object etag contains ", e.g.: "5B3C1A2E053D763E1B002CC607C5A0FE"
  2482. example:
  2483. ```js
  2484. const name = 'object';
  2485. const result = await store.initMultipartUpload(name);
  2486. const partSize = 100 * 1024; //100kb
  2487. //if file part is 10
  2488. for (let i = 1; i <= 10; i++) {
  2489. const start = partSize * (i - 1);
  2490. const end = Math.min(start + partSize, fileSize);
  2491. const range = start + '-' + (end - 1);
  2492. const part = await store.uploadPartCopy(name, result.uploadId, i, range, {
  2493. sourceKey: 'sourceKey',
  2494. sourceBucketName: 'sourceBucketName'
  2495. });
  2496. console.log(part);
  2497. }
  2498. //end need complete api
  2499. ```
  2500. - use history object to uploadPartCopy
  2501. ```js
  2502. const versionId = 'object versionId';
  2503. const name = 'object';
  2504. const result = await store.initMultipartUpload(name);
  2505. const partSize = 100 * 1024; //100kb
  2506. //if file part is 10
  2507. for (let i = 1; i <= 10; i++) {
  2508. const start = partSize * (i - 1);
  2509. const end = Math.min(start + partSize, fileSize);
  2510. const range = start + '-' + (end - 1);
  2511. const part = await store.uploadPartCopy(
  2512. name,
  2513. result.uploadId,
  2514. i,
  2515. range,
  2516. {
  2517. sourceKey: 'sourceKey',
  2518. sourceBucketName: 'sourceBucketName'
  2519. },
  2520. {
  2521. versionId
  2522. }
  2523. );
  2524. console.log(part);
  2525. }
  2526. //end need complete api
  2527. ```
  2528. ### .completeMultipartUpload(name, uploadId, parts[, options])
  2529. After uploading all data parts, you must call the Complete Multipart Upload API to complete Multipart Upload for the entire file.
  2530. parameters:
  2531. - name {String} object name
  2532. - uploadId {String} get by initMultipartUpload api
  2533. - parts {Array} more part {Object} from uploadPartCopy, , each in the structure:
  2534. - number {Number} partNo
  2535. - etag {String} object etag contains ", e.g.: "5B3C1A2E053D763E1B002CC607C5A0FE"
  2536. - [options] {Object} optional parameters
  2537. - [timeout] {Number} the operation timeout
  2538. - [callback] {Object} The callback parameter is composed of a JSON string encoded in Base64,detail [see](https://www.alibabacloud.com/help/doc-detail/31989.htm)<br>
  2539. - url {String} After a file is uploaded successfully, the OSS sends a callback request to this URL.
  2540. - [host] {String} The host header value for initiating callback requests.
  2541. - body {String} The value of the request body when a callback is initiated, for example, key=${key}&etag=${etag}&my_var=${x:my_var}.
  2542. - [contentType] {String} The Content-Type of the callback requests initiatiated, It supports application/x-www-form-urlencoded and application/json, and the former is the default value.
  2543. - [callbackSNI] {Boolean} Specifies whether OSS sends Server Name Indication (SNI) to the origin address specified by callbackUrl when a callback request is initiated from the client.
  2544. - [customValue] {Object} Custom parameters are a map of key-values<br>
  2545. e.g.:
  2546. ```js
  2547. var customValue = { var1: 'value1', var2: 'value2' };
  2548. ```
  2549. - [headers] {Object} extra headers, detail see [CompleteMultipartUpload](https://help.aliyun.com/document_detail/31995.html?#title-nan-5y3-rjd)
  2550. Success will return:
  2551. - res {Object} response info, including
  2552. - status {Number} response status
  2553. - headers {Object} response headers
  2554. - size {Number} response size
  2555. - rt {Number} request total use time (ms)
  2556. - bucket {String} bucket name
  2557. - name {String} object name store on OSS
  2558. - etag {String} object etag contains ", e.g.: "5B3C1A2E053D763E1B002CC607C5A0FE"
  2559. - data {Object} callback server response data , sdk use JSON.parse() return
  2560. example:
  2561. ```js
  2562. //init multipart
  2563. const name = 'object';
  2564. const result = await store.initMultipartUpload(name);
  2565. //upload part
  2566. const file; //the data you want to upload, this example size is 10 * 100 * 1024
  2567. const fileSize;//you need to calculate
  2568. const partSize = 100 * 1024;//100kb
  2569. const done = [];
  2570. //if file part is 10
  2571. for (let i = 1; i <= 10; i++) {
  2572. const start = partSize * (i -1);
  2573. const end = Math.min(start + partSize, fileSize);
  2574. const data = file.slice(start, end);
  2575. const part = store.uploadPart(name, result.uploadId, i, data, 0, data.length);
  2576. console.log(part);
  2577. done.push({
  2578. number: i,
  2579. etag: part.res.headers.etag
  2580. });
  2581. }
  2582. //complete
  2583. const completeData = await store.completeMultipartUpload(name, result.uploadId, done);
  2584. console.log(completeData);
  2585. ```
  2586. ### .multipartUpload(name, file[, options])
  2587. Upload file with [OSS multipart][oss-multipart].<br>
  2588. this function contains initMultipartUpload, uploadPart, completeMultipartUpload.
  2589. When you use multipartUpload api,if you encounter problems with ConnectionTimeoutError, you should handle ConnectionTimeoutError in your business code. How to resolve ConnectionTimeoutError, you can decrease `partSize` size 、 Increase `timeout` 、Retry request ,
  2590. or give tips in your business code;
  2591. parameters:
  2592. - name {String} object name
  2593. - file {String|File(only support Browser)|Blob(only support Browser)|Buffer} file path or HTML5 Web File or web Blob or content buffer
  2594. - [options] {Object} optional args
  2595. - [parallel] {Number} the number of parts to be uploaded in parallel
  2596. - [partSize] {Number} the suggested size for each part, default `1024 * 1024`(1MB), minimum `100 * 1024`(100KB)
  2597. - [progress] {Function} function | async | Promise, the progress callback called after each
  2598. successful upload of one part, it will be given three parameters:
  2599. (percentage {Number}, checkpoint {Object}, res {Object})
  2600. - [checkpoint] {Object} the checkpoint to resume upload, if this is
  2601. provided, it will continue the upload from where interrupted,
  2602. otherwise a new multipart upload will be created.
  2603. - file {File} The file object selected by the user, if the browser is restarted, it needs the user to manually trigger the settings
  2604. - name {String} object key
  2605. - fileSize {Number} file size
  2606. - partSize {Number} part size
  2607. - uploadId {String} upload id
  2608. - doneParts {Array} An array of pieces that have been completed, including the object structure as follows
  2609. - number {Number} part number
  2610. - etag {String} part etag
  2611. - [meta] {Object} user meta, will send with `x-oss-meta-` prefix string
  2612. - [mime] {String} custom mime , will send with `Content-Type` entity header
  2613. - [callback] {Object} The callback parameter is composed of a JSON string encoded in Base64,detail [see](https://www.alibabacloud.com/help/doc-detail/31989.htm)<br>
  2614. - url {String} After a file is uploaded successfully, the OSS sends a callback request to this URL.
  2615. - [host] {String} The host header value for initiating callback requests.
  2616. - body {String} The value of the request body when a callback is initiated, for example, key=${key}&etag=${etag}&my_var=${x:my_var}.
  2617. - [contentType] {String} The Content-Type of the callback requests initiatiated, It supports application/x-www-form-urlencoded and application/json, and the former is the default value.
  2618. - [callbackSNI] {Boolean} Specifies whether OSS sends Server Name Indication (SNI) to the origin address specified by callbackUrl when a callback request is initiated from the client.
  2619. - [customValue] {Object} Custom parameters are a map of key-values<br>
  2620. e.g.:
  2621. ```js
  2622. var customValue = { var1: 'value1', var2: 'value2' };
  2623. ```
  2624. - [headers] {Object} extra headers, detail see [RFC 2616](http://www.w3.org/Protocols/rfc2616/rfc2616.html)
  2625. - 'Cache-Control' cache control for download, e.g.: `Cache-Control: public, no-cache`
  2626. - 'Content-Disposition' object name for download, e.g.: `Content-Disposition: somename`
  2627. - 'Content-Encoding' object content encoding for download, e.g.: `Content-Encoding: gzip`
  2628. - 'Expires' expires time for download, an absolute date and time. e.g.: `Tue, 08 Dec 2020 13:49:43 GMT`
  2629. - **NOTE**: Some headers are [disabled in browser][disabled-browser-headers]
  2630. - [timeout] {Number} Milliseconds before a request is considered to be timed out
  2631. - [disabledMD5] {Boolean} default true, it just work in Browser. if false,it means that MD5 is automatically calculated for uploaded files. **_NOTE:_** Synchronous computing tasks will block the main process
  2632. Success will return:
  2633. - res {Object} response info, including
  2634. - status {Number} response status
  2635. - headers {Object} response headers
  2636. - size {Number} response size
  2637. - rt {Number} request total use time (ms)
  2638. - bucket {String} bucket name
  2639. - name name {String} object name store on OSS
  2640. - etag {String} object etag contains ", e.g.: "5B3C1A2E053D763E1B002CC607C5A0FE"
  2641. - data {Object} callback server response data, sdk use JSON.parse() return
  2642. example:
  2643. - Upload using multipart
  2644. ```js
  2645. const result = await store.multipartUpload('object', '/tmp/file');
  2646. let savedCpt;
  2647. console.log(result);
  2648. const result = await store.multipartUpload('object', '/tmp/file', {
  2649. parallel: 4,
  2650. partSize: 1024 * 1024,
  2651. progress: function (p, cpt, res) {
  2652. console.log(p);
  2653. savedCpt = cpt;
  2654. console.log(cpt);
  2655. console.log(res.headers['x-oss-request-id']);
  2656. }
  2657. });
  2658. const result = await store.multipartUpload('object', '/tmp/file', {
  2659. checkpoint: savedCpt,
  2660. progress: function (p, cpt, res) {
  2661. //progress is generator
  2662. console.log(p);
  2663. console.log(cpt);
  2664. console.log(res.headers['x-oss-request-id']);
  2665. }
  2666. });
  2667. ```
  2668. - multipartUpload progress example
  2669. ```js
  2670. //async function
  2671. async function asyncProgress(p, cpt, res) {
  2672. console.log(p);
  2673. console.log(cpt);
  2674. console.log(res.headers['x-oss-request-id']);
  2675. }
  2676. const result1 = await store.multipartUpload('object', '/tmp/file', {
  2677. progress: asyncProgress
  2678. });
  2679. //function
  2680. function progress(p, cpt, res) {
  2681. console.log(p);
  2682. console.log(cpt);
  2683. console.log(res.headers['x-oss-request-id']);
  2684. }
  2685. const result2 = await store.multipartUpload('object', '/tmp/file', {
  2686. progress: progress
  2687. });
  2688. ```
  2689. - multipartUpload with abort
  2690. > tips: abort multipartUpload support on node and browser
  2691. ```js
  2692. //start upload
  2693. let abortCheckpoint;
  2694. store.multipartUpload('object', '/tmp/file', {
  2695. progress: function (p, cpt, res) {
  2696. abortCheckpoint = cpt;
  2697. }
  2698. }).then(res => {
  2699. // do something
  2700. }).catch(err => {
  2701. //if abort will catch abort event
  2702. if (err.name === 'abort') {
  2703. // handle abort
  2704. console.log('error: ', err.message)
  2705. }
  2706. });
  2707. // abort
  2708. store.abortMultipartUpload(abortCheckpoint.name, abortCheckpoint.uploadId);
  2709. ```
  2710. - multipartUpload with cancel
  2711. > tips: cancel multipartUpload support on node and browser
  2712. ```js
  2713. //start upload
  2714. try {
  2715. const result = await store.multipartUpload('object', '/tmp/file', {
  2716. checkpoint: savedCpt,
  2717. progress: function (p, cpt, res) {
  2718. console.log(p);
  2719. console.log(cpt);
  2720. console.log(res.headers['x-oss-request-id']);
  2721. }
  2722. });
  2723. } catch (err) {
  2724. //if cancel will catch cancel event
  2725. if (store.isCancel()) {
  2726. //do something
  2727. }
  2728. }
  2729. //the other event to cancel, for example: click event
  2730. //to cancel upload must use the same client instance
  2731. store.cancel();
  2732. ```
  2733. - multipartUpload with capture `ConnectionTimeoutError` error
  2734. ```js
  2735. //start upload
  2736. try {
  2737. const result = await store.multipartUpload('object', '/tmp/file', {
  2738. checkpoint: savedCpt,
  2739. progress: function (p, cpt, res) {
  2740. console.log(p);
  2741. console.log(cpt);
  2742. console.log(res.headers['x-oss-request-id']);
  2743. }
  2744. });
  2745. } catch (err) {
  2746. if (err.code === 'ConnectionTimeoutError') {
  2747. console.log('Woops,Woops ,timeout error!!!');
  2748. // do ConnectionTimeoutError operation
  2749. }
  2750. }
  2751. ```
  2752. ### .multipartUploadCopy(name, sourceData[, options])
  2753. Copy file with [OSS multipart][oss-multipart]. <br>
  2754. this function contains head, initMultipartUpload, uploadPartCopy, completeMultipartUpload.<br>
  2755. When copying a file larger than 1 GB, you should use the Upload Part Copy method. If you want to copy a file smaller than 1 GB, see Copy Object.
  2756. parameters:
  2757. - name {String} object name
  2758. - file {String|File} file path or HTML5 Web File
  2759. - [options] {Object} optional args
  2760. - [timeout] {Number} Milliseconds before a request is considered to be timed out
  2761. - [parallel] {Number} the number of parts to be uploaded in parallel
  2762. - [partSize] {Number} the suggested size for each part, defalut `1024 * 1024`(1MB), minimum `100 * 1024`(100KB)
  2763. - [versionId] {String} the version id of history object
  2764. - [progress] {Function} function | async | Promise, the progress callback called after each
  2765. successful upload of one part, it will be given three parameters:
  2766. (percentage {Number}, checkpoint {Object}, res {Object})
  2767. - [checkpoint] {Object} the checkpoint to resume upload, if this is
  2768. provided, it will continue the upload from where interrupted,
  2769. otherwise a new multipart upload will be created.
  2770. - [headers] {Object} extra headers, detail see [RFC 2616](http://www.w3.org/Protocols/rfc2616/rfc2616.html)
  2771. - 'Cache-Control' cache control for download, e.g.: `Cache-Control: public, no-cache`
  2772. - 'Content-Disposition' object name for download, e.g.: `Content-Disposition: somename`
  2773. - 'Content-Encoding' object content encoding for download, e.g.: `Content-Encoding: gzip`
  2774. - 'Expires' expires time for download, an absolute date and time. e.g.: `Tue, 08 Dec 2020 13:49:43 GMT`
  2775. - **NOTE**: Some headers are [disabled in browser][disabled-browser-headers]
  2776. - [copyheaders] {Object} only uploadPartCopy api used, detail [see](https://www.alibabacloud.com/help/doc-detail/31994.htm)
  2777. - [x-oss-copy-source-if-match] only uploadPartCopy api used, default none<br>
  2778. If the ETAG value of the source object is equal to the ETAG value provided by the user, the system performs the Copy Object operation; otherwise, the system returns the 412 Precondition Failed message.
  2779. - [x-oss-copy-source-if-none-match] only uploadPartCopy api used, default none<br>
  2780. If the source object has not been modified since the time specified by the user, the system performs the Copy Object operation; otherwise, the system returns the 412 Precondition Failed message.
  2781. - [x-oss-copy-source-if-unmodified-since] only uploadPartCopy api used, default none<br>
  2782. If the time specified by the received parameter is the same as or later than the modification time of the file, the system transfers the file normally, and returns 200 OK; otherwise, the system returns 412 Precondition Failed.
  2783. - [x-oss-copy-source-if-modified-since] only uploadPartCopy api used, default none<br>
  2784. If the source object has been modified since the time specified by the user, the system performs the Copy Object operation; otherwise, the system returns the 412 Precondition Failed message.
  2785. Success will return:
  2786. - res {Object} response info, including
  2787. - status {Number} response status
  2788. - headers {Object} response headers
  2789. - size {Number} response size
  2790. - rt {Number} request total use time (ms)
  2791. - bucket {String} bucket name
  2792. - name name {String} object name store on OSS
  2793. - etag {String} object etag contains ", e.g.: "5B3C1A2E053D763E1B002CC607C5A0FE"
  2794. example:
  2795. - Copy using multipart
  2796. ```js
  2797. const result = await store.multipartUploadCopy('object', {
  2798. sourceKey: 'sourceKey',
  2799. sourceBucketName: 'sourceBucketName'
  2800. });
  2801. let savedCpt;
  2802. console.log(result);
  2803. const result = await store.multipartUploadCopy(
  2804. 'object',
  2805. {
  2806. sourceKey: 'sourceKey',
  2807. sourceBucketName: 'sourceBucketName'
  2808. },
  2809. {
  2810. parallel: 4,
  2811. partSize: 1024 * 1024,
  2812. progress: function (p, cpt, res) {
  2813. console.log(p);
  2814. savedCpt = cpt;
  2815. console.log(cpt);
  2816. console.log(res.headers['x-oss-request-id']);
  2817. }
  2818. }
  2819. );
  2820. console.log(result);
  2821. const result = await store.multipartUploadCopy(
  2822. 'object',
  2823. {
  2824. sourceKey: 'sourceKey',
  2825. sourceBucketName: 'sourceBucketName'
  2826. },
  2827. {
  2828. checkpoint: savedCpt,
  2829. progress: function (p, cpt, res) {
  2830. console.log(p);
  2831. console.log(cpt);
  2832. console.log(res.headers['x-oss-request-id']);
  2833. }
  2834. }
  2835. );
  2836. console.log(result);
  2837. ```
  2838. - multipartUploadCopy with abort
  2839. ```js
  2840. // start upload
  2841. let abortCheckpoint;
  2842. store.multipartUploadCopy('object', {
  2843. sourceKey: 'sourceKey',
  2844. sourceBucketName: 'sourceBucketName'
  2845. }, {
  2846. progress: function (p, cpt, res) {
  2847. abortCheckpoint = cpt;
  2848. }
  2849. }).then(res => {
  2850. // do something
  2851. }).catch(err => {
  2852. //if abort will catch abort event
  2853. if (err.name === 'abort') {
  2854. // handle abort
  2855. console.log('error: ', err.message)
  2856. }
  2857. });
  2858. // the other event to abort, for example: click event
  2859. // to abort upload must use the same client instance
  2860. store.abortMultipartUpload(abortCheckpoint.name, abortCheckpoint.uploadId);
  2861. ```
  2862. - multipartUploadCopy with cancel
  2863. ```js
  2864. //start upload
  2865. try {
  2866. const result = await store.multipartUploadCopy(
  2867. 'object',
  2868. {
  2869. sourceKey: 'sourceKey',
  2870. sourceBucketName: 'sourceBucketName'
  2871. },
  2872. {
  2873. checkpoint: savedCpt,
  2874. progress: function (p, cpt, res) {
  2875. console.log(p);
  2876. console.log(cpt);
  2877. console.log(res.headers['x-oss-request-id']);
  2878. }
  2879. }
  2880. );
  2881. } catch (err) {
  2882. //if cancel will catch cancel event
  2883. if (store.isCancel()) {
  2884. //do something
  2885. }
  2886. }
  2887. //the other event to cancel, for example: click event
  2888. //to cancel upload must use the same client instance
  2889. store.cancel();
  2890. ```
  2891. - multipartUploadCopy with versionId
  2892. ```js
  2893. const versionId = 'object versionId';
  2894. //start upload
  2895. const result = await store.multipartUploadCopy(
  2896. 'object',
  2897. {
  2898. sourceKey: 'sourceKey',
  2899. sourceBucketName: 'sourceBucketName'
  2900. },
  2901. {
  2902. checkpoint: savedCpt,
  2903. progress: function (p, cpt, res) {
  2904. console.log(p);
  2905. console.log(cpt);
  2906. console.log(res.headers['x-oss-request-id']);
  2907. },
  2908. versionId
  2909. }
  2910. );
  2911. ```
  2912. ### .listParts(name, uploadId[, query, options])
  2913. The ListParts command can be used to list all successfully uploaded parts mapped to a specific upload ID, i.e.: those not completed and not
  2914. aborted.
  2915. parameters:
  2916. - name {String} object key
  2917. - uploadId {String} upload ID from initMultipartUpload api
  2918. - [query] {Object} query parameters
  2919. - [max-parts] {Number} The maximum part number in the response of the OSS. default value: 1000.
  2920. - [part-number-marker] {Number} Starting position of a specific list. A part is listed only when the part number is greater than the value of this parameter.
  2921. - [encoding-type] {String} Specify the encoding of the returned content and the encoding type. Optional value: url
  2922. - [options] {Object} optional args
  2923. - [timeout] {Number} the operation timeout
  2924. Success will return:
  2925. - res {Object} response info, including
  2926. - status {Number} response status
  2927. - headers {Object} response headers
  2928. - size {Number} response size
  2929. - rt {Number} request total use time (ms)
  2930. - uploadId {String} upload ID
  2931. - bucket {String} Specify the bucket name.
  2932. - name {String} object name
  2933. - PartNumberMarker {Number} Starting position of the part numbers in the listing result.
  2934. - nextPartNumberMarker {Number} If not all results are returned this time, the response request includes the NextPartNumberMarker element to indicate the value of PartNumberMarker in the next request.
  2935. - maxParts {Number} upload ID
  2936. - isTruncated {Boolean} Whether the returned result list for List Parts is truncated. The “true” indicates that not all results are returned; “false” indicates that all results are returned.
  2937. - parts {Array} The container that saves part information, each in the structure:
  2938. - PartNumber {Number} Part number.
  2939. - LastModified {Date} Time when a part is uploaded.
  2940. - ETag {String} ETag value in the content of the uploaded part.
  2941. - Size {Number} Size of the uploaded part.
  2942. example:
  2943. - List uploaded part
  2944. ```js
  2945. const result = await store.listParts('objcet', 'uploadId', {
  2946. 'max-parts': 1000
  2947. });
  2948. console.log(result);
  2949. ```
  2950. ### .listUploads(query[, options])
  2951. List on-going multipart uploads, i.e.: those not completed and not
  2952. aborted.
  2953. parameters:
  2954. - query {Object} query parameters
  2955. - [prefix] {String} the object key prefix
  2956. - [max-uploads] {Number} the max uploads to return
  2957. - [key-marker] {String} the object key marker, if `upload-id-marker`
  2958. is not provided, return uploads with `key > marker`, otherwise
  2959. return uploads with `key >= marker && uploadId > id-marker`
  2960. - [upload-id-marker] {String} the upload id marker, must be used
  2961. **WITH** `key-marker`
  2962. - [options] {Object} optional args
  2963. - [timeout] {Number} the operation timeout
  2964. example:
  2965. - List on-going multipart uploads
  2966. ```js
  2967. const result = await store.listUploads({
  2968. 'max-uploads': 100,
  2969. 'key-marker': 'my-object',
  2970. 'upload-id-marker': 'upload-id'
  2971. });
  2972. console.log(result);
  2973. ```
  2974. ### .abortMultipartUpload(name, uploadId[, options])
  2975. Abort a multipart upload for object.
  2976. parameters:
  2977. - name {String} the object name
  2978. - uploadId {String} the upload id
  2979. - [options] {Object} optional args
  2980. - [timeout] {Number} the operation timeout
  2981. example:
  2982. - Abort a multipart upload
  2983. ```js
  2984. const result = await store.abortMultipartUpload('object', 'upload-id');
  2985. console.log(result);
  2986. ```
  2987. ### .calculatePostSignature(policy)
  2988. get postObject params
  2989. parameters:
  2990. - policy {JSON or Object} policy must contain expiration and conditions.
  2991. Success will return postObject Api params.
  2992. Object:
  2993. - OSSAccessKeyId {String}
  2994. - Signature {String}
  2995. - policy {Object} response info
  2996. ### .signPostObjectPolicyV4(policy, date)
  2997. Get a V4 signature of the PostObject request.
  2998. parameters:
  2999. - policy {string | Object} The policy form field in a PostObject request is used to specify the expiration time and conditions of the PostObject request that you initiate to upload an object by using an HTML form. The value of the policy form field is a JSON string or an object.
  3000. - date {Date} The time when the request was initiated.
  3001. Success will return a V4 signature of the PostObject request.
  3002. example:
  3003. ```js
  3004. const axios = require('axios');
  3005. const dateFormat = require('dateformat');
  3006. const FormData = require('form-data');
  3007. const { getCredential } = require('ali-oss/lib/common/signUtils');
  3008. const { getStandardRegion } = require('ali-oss/lib/common/utils/getStandardRegion');
  3009. const { policy2Str } = require('ali-oss/lib/common/utils/policy2Str');
  3010. const OSS = require('ali-oss');
  3011. const client = new OSS({
  3012. accessKeyId: 'yourAccessKeyId',
  3013. accessKeySecret: 'yourAccessKeySecret',
  3014. stsToken: 'yourSecurityToken',
  3015. bucket: 'yourBucket',
  3016. region: 'oss-cn-hangzhou'
  3017. });
  3018. const name = 'yourObjectName';
  3019. const formData = new FormData();
  3020. formData.append('key', name);
  3021. formData.append('Content-Type', 'yourObjectContentType');
  3022. // your object cache control
  3023. formData.append('Cache-Control', 'max-age=30');
  3024. const url = client.generateObjectUrl(name).replace(name, '');
  3025. const date = new Date();
  3026. // The expiration parameter specifies the expiration time of the request.
  3027. const expirationDate = new Date(date);
  3028. expirationDate.setMinutes(date.getMinutes() + 1);
  3029. // The time must follow the ISO 8601 standard
  3030. const formattedDate = dateFormat(date, "UTC:yyyymmdd'T'HHMMss'Z'");
  3031. const credential = getCredential(formattedDate.split('T')[0], getStandardRegion(client.options.region), client.options.accessKeyId);
  3032. formData.append('x-oss-date', formattedDate);
  3033. formData.append('x-oss-credential', credential);
  3034. formData.append('x-oss-signature-version', 'OSS4-HMAC-SHA256');
  3035. const policy = {
  3036. expiration: expirationDate.toISOString(),
  3037. conditions: [
  3038. { bucket: client.options.bucket },
  3039. {'x-oss-credential': credential},
  3040. {'x-oss-date': formattedDate},
  3041. {'x-oss-signature-version': 'OSS4-HMAC-SHA256'},
  3042. ['content-length-range', 1, 10],
  3043. ['eq', '$success_action_status', '200'],
  3044. ['starts-with', '$key', 'yourObjectName'],
  3045. ['in', '$content-type', ['image/jpg', 'text/plain']],
  3046. ['not-in', '$cache-control', ['no-cache']]
  3047. ]
  3048. };
  3049. if (client.options.stsToken) {
  3050. policy.conditions.push({'x-oss-security-token': client.options.stsToken});
  3051. formData.append('x-oss-security-token', client.options.stsToken);
  3052. }
  3053. const signature = client.signPostObjectPolicyV4(policy, date);
  3054. formData.append('policy', Buffer.from(policy2Str(policy), 'utf8').toString('base64'));
  3055. formData.append('x-oss-signature', signature);
  3056. formData.append('success_action_status', '200');
  3057. formData.append('file', 'yourFileContent');
  3058. axios.post(url, formData, {
  3059. headers: {
  3060. 'Content-Type': 'multipart/form-data'
  3061. }
  3062. }).then((result) => {
  3063. console.log(result.status);
  3064. }).catch((e) => {
  3065. console.log(e);
  3066. });
  3067. ```
  3068. ### .getObjectTagging(name[, options])
  3069. Obtains the tags of an object.
  3070. parameters:
  3071. - name {String} the object name
  3072. - [options] {Object} optional args
  3073. - [versionId] {String} the version id of history object
  3074. Success will return the channel information.
  3075. object:
  3076. - tag {Object} the tag of object
  3077. - res {Object} response info
  3078. ### .putObjectTagging(name, tag[, options])
  3079. Configures or updates the tags of an object.
  3080. parameters:
  3081. - name {String} the object name
  3082. - tag {Object} tag, eg. `{var1: value1,var2:value2}`
  3083. - [options] {Object} optional args
  3084. - [versionId] {String} the version id of history object
  3085. Success will return the channel information.
  3086. object:
  3087. - status {Number} response status
  3088. - res {Object} response info
  3089. ### .deleteObjectTagging(name[, options])
  3090. Deletes the tag of a specified object.
  3091. parameters:
  3092. - name {String} the object name
  3093. - tag {Object} tag, eg. `{var1: value1,var2:value2}`
  3094. - [options] {Object} optional args
  3095. - [versionId] {String} the version id of history object
  3096. Success will return the channel information.
  3097. object:
  3098. - status {Number} response status
  3099. - res {Object} response info
  3100. ### .processObjectSave(sourceObject, targetObject, process[, targetBucket])
  3101. Persistency indicates that images are asynchronously stored in the specified Bucket
  3102. parameters:
  3103. - sourceObject {String} source object name
  3104. - targetObject {String} target object name
  3105. - process {String} process string
  3106. - [targetBucket] {String} target bucket
  3107. Success will return the channel information.
  3108. object:
  3109. - status {Number} response status
  3110. - res {Object} response info
  3111. ```js
  3112. const sourceObject = 'a.png';
  3113. const targetObject = 'b.png';
  3114. const process = 'image/watermark,text_aGVsbG8g5Zu+54mH5pyN5Yqh77yB,color_ff6a00';
  3115. await this.store.processObjectSave(sourceObject, targetObject, process);
  3116. ```
  3117. ## RTMP Operations
  3118. All operations function is [async], except `getRtmpUrl`.
  3119. async function format: `async functionName(...)`.
  3120. ### .putChannel(id, conf[, options])
  3121. Create a live channel.
  3122. parameters:
  3123. - id {String} the channel id
  3124. - conf {Object} the channel config
  3125. - [Description] {String} the channel description
  3126. - [Status] {String} the channel status: 'enabled' or 'disabled'
  3127. - [Target] {Object}
  3128. - [Type] {String} the data type for the channel, only 'HLS' is supported now
  3129. - [FragDuration] {Number} duration of a 'ts' segment
  3130. - [FragCount] {Number} the number of 'ts' segments in a 'm3u8'
  3131. - [PlaylistName] {String} the 'm3u8' name
  3132. - [options] {Object} optional parameters
  3133. - [timeout] {Number} the operation timeout
  3134. Success will return the channel information.
  3135. object:
  3136. - publishUrls {Array} the publish urls
  3137. - playUrls {Array} the play urls
  3138. - res {Object} response info
  3139. example:
  3140. - Create a live channel
  3141. ```js
  3142. const cid = 'my-channel';
  3143. const conf = {
  3144. Description: 'this is channel 1',
  3145. Status: 'enabled',
  3146. Target: {
  3147. Type: 'HLS',
  3148. FragDuration: '10',
  3149. FragCount: '5',
  3150. PlaylistName: 'playlist.m3u8'
  3151. }
  3152. };
  3153. const r = await this.store.putChannel(cid, conf);
  3154. console.log(r);
  3155. ```
  3156. ### .getChannel(id[, options])
  3157. Get live channel info.
  3158. parameters:
  3159. - id {String} the channel id
  3160. - [options] {Object} optional parameters
  3161. - [timeout] {Number} the operation timeout
  3162. Success will return the channel information.
  3163. object:
  3164. - data {Object} channel info, same as conf in [.putChannel](#putchannelid-conf-options)
  3165. - res {Object} response info
  3166. example:
  3167. - Get live channel info
  3168. ```js
  3169. const cid = 'my-channel';
  3170. const r = await this.store.getChannel(cid);
  3171. console.log(r);
  3172. ```
  3173. ### .deleteChannel(id[, options])
  3174. Delete a live channel.
  3175. parameters:
  3176. - id {String} the channel id
  3177. - [options] {Object} optional parameters
  3178. - [timeout] {Number} the operation timeout
  3179. Success will return the response infomation.
  3180. object:
  3181. - res {Object} response info
  3182. example:
  3183. - Delete a live channel
  3184. ```js
  3185. const cid = 'my-channel';
  3186. const r = await this.store.deleteChannel(cid);
  3187. console.log(r);
  3188. ```
  3189. ### .putChannelStatus(id, status[, options])
  3190. Change the live channel status.
  3191. parameters:
  3192. - id {String} the channel id
  3193. - status {String} the status: 'enabled' or 'disabled'
  3194. - [options] {Object} optional parameters
  3195. - [timeout] {Number} the operation timeout
  3196. Success will return the response information.
  3197. object:
  3198. - res {Object} response info
  3199. example:
  3200. - Disable a live channel
  3201. ```js
  3202. const cid = 'my-channel';
  3203. const r = await this.store.putChannelStatus(cid, 'disabled');
  3204. console.log(r);
  3205. ```
  3206. ### .getChannelStatus(id[, options])
  3207. Get the live channel status.
  3208. parameters:
  3209. - id {String} the channel id
  3210. - [options] {Object} optional parameters
  3211. - [timeout] {Number} the operation timeout
  3212. Success will return the channel status information.
  3213. object:
  3214. - data {Object}
  3215. - Status {String} the channel status: 'Live' or 'Idle'
  3216. - [ConnectedTime] {String} the connected time of rtmp pushing
  3217. - [RemoteAddr] {String} the remote addr of rtmp pushing
  3218. - [Video] {Object} the video parameters (Width/Height/FrameRate/Bandwidth/Codec)
  3219. - [Audio] {Object} the audio parameters (Bandwidth/SampleRate/Codec)
  3220. - res {Object} response info
  3221. example:
  3222. - Get a live channel status
  3223. ```js
  3224. const cid = 'my-channel';
  3225. const r = await this.store.getChannelStatus(cid);
  3226. console.log(r);
  3227. // { Status: 'Live',
  3228. // ConnectedTime: '2016-04-12T11:51:03.000Z',
  3229. // RemoteAddr: '42.120.74.98:53931',
  3230. // Video:
  3231. // { Width: '672',
  3232. // Height: '378',
  3233. // FrameRate: '29',
  3234. // Bandwidth: '60951',
  3235. // Codec: 'H264' },
  3236. // Audio: { Bandwidth: '5959', SampleRate: '22050', Codec: 'AAC' }
  3237. // }
  3238. ```
  3239. ### .listChannels(query[, options])
  3240. List channels.
  3241. parameters:
  3242. - query {Object} parameters for list
  3243. - prefix {String}: the channel id prefix (returns channels with this prefix)
  3244. - marker {String}: the channle id marker (returns channels after this id)
  3245. - max-keys {Number}: max number of channels to return
  3246. - [options] {Object} optional parameters
  3247. - [timeout] {Number} the operation timeout
  3248. Success will return the channel list.
  3249. object:
  3250. - channels {Array} the channels, each in the structure:
  3251. - Name {String} the channel id
  3252. - Description {String} the channel description
  3253. - Status {String} the channel status
  3254. - LastModified {String} the last modification time of the channel
  3255. - PublishUrls {Array} the publish urls for the channel
  3256. - PlayUrls {Array} the play urls for the channel
  3257. - nextMarker: result.data.NextMarker || null,
  3258. - isTruncated: result.data.IsTruncated === 'true'
  3259. - res {Object} response info
  3260. example:
  3261. - List live channels
  3262. ```js
  3263. const r = await this.store.listChannels({
  3264. prefix: 'my-channel',
  3265. 'max-keys': 3
  3266. });
  3267. console.log(r);
  3268. ```
  3269. ### .getChannelHistory(id[, options])
  3270. Get the live channel history.
  3271. parameters:
  3272. - id {String} the channel id
  3273. - [options] {Object} optional parameters
  3274. - [timeout] {Number} the operation timeout
  3275. Success will return the history information.
  3276. object:
  3277. - records {Object} the pushing records, each in the structure:
  3278. - StartTime {String} the start time
  3279. - EndTime {String} the end time
  3280. - RemoteAddr {String} the remote addr
  3281. - res {Object} response info
  3282. example:
  3283. - Get the live channel history
  3284. ```js
  3285. const cid = 'my-channel';
  3286. const r = await this.store.getChannelHistory(cid);
  3287. console.log(r);
  3288. ```
  3289. ### .createVod(id, name, time[, options])
  3290. Create a VOD playlist for the channel.
  3291. parameters:
  3292. - id {String} the channel id
  3293. - name {String} the playlist name
  3294. - time {Object} the duration time
  3295. - startTime {Number} the start time in epoch seconds
  3296. - endTime {Number} the end time in epoch seconds
  3297. - [options] {Object} optional parameters
  3298. - [timeout] {Number} the operation timeout
  3299. Success will return the response information.
  3300. object:
  3301. - res {Object} response info
  3302. example:
  3303. - Create a vod playlist of a live channel
  3304. ```js
  3305. const cid = 'my-channel';
  3306. const r = await this.store.createVod(cid, 're-play', {
  3307. startTime: 1460464870,
  3308. endTime: 1460465877
  3309. });
  3310. console.log(r);
  3311. ```
  3312. ### .getRtmpUrl(channelId[, options])
  3313. Get signatured rtmp url for publishing.
  3314. parameters:
  3315. - channelId {String} the channel id
  3316. - [options] {Object} optional parameters
  3317. - [expires] {Number} the expire time in seconds of the url
  3318. - [params] {Object} the additional paramters for url, e.g.: {playlistName: 'play.m3u8'}
  3319. - [timeout] {Number} the operation timeout
  3320. Success will return the rtmp url.
  3321. example:
  3322. - Get a rtmp url.
  3323. ```js
  3324. const cid = 'my-channel';
  3325. const url = this.store.getRtmpUrl(this.cid, {
  3326. params: {
  3327. playlistName: 'play.m3u8'
  3328. },
  3329. expires: 3600
  3330. });
  3331. console.log(url);
  3332. // rtmp://ossliveshow.oss-cn-hangzhou.aliyuncs.com/live/tl-channel?OSSAccessKeyId=T0cqQWBk2ThfRS6m&Expires=1460466188&Signature=%2BnzTtpyxUWDuQn924jdS6b51vT8%3D
  3333. ```
  3334. ## Create A Image Service Instance
  3335. Each Image Service instance required `accessKeyId`, `accessKeySecret`, `bucket` and `imageHost`.
  3336. ### oss.ImageClient(options)
  3337. Create a Image service instance.
  3338. options:
  3339. - imageHost {String} your image service domain that binding to a OSS bucket
  3340. - accessKeyId {String} access key you create on aliyun console website
  3341. - accessKeySecret {String} access secret you create
  3342. - bucket {String} the default bucket you want to access
  3343. If you don't have any bucket, please use `putBucket()` create one first.
  3344. - [region] {String} the bucket data region location, please see [Data Regions](#data-regions),
  3345. default is `oss-cn-hangzhou`
  3346. Current available: `oss-cn-hangzhou`, `oss-cn-qingdao`, `oss-cn-beijing`, `oss-cn-hongkong` and `oss-cn-shenzhen`
  3347. - [internal] {Boolean} access OSS with aliyun internal network or not, default is `false`
  3348. If your servers are running on aliyun too, you can set `true` to save lot of money.
  3349. - [timeout] {String|Number} instance level timeout for all operations, default is `60s`
  3350. example:
  3351. ```js
  3352. const oss = require('ali-oss');
  3353. const imgClient = oss.ImageClient({
  3354. accessKeyId: 'your access key',
  3355. accessKeySecret: 'your access secret',
  3356. bucket: 'my_image_bucket',
  3357. imageHost: 'thumbnail.myimageservice.com'
  3358. });
  3359. ```
  3360. ## Image Operations
  3361. All operations function is [async], except `imgClient.signatureUrl`.
  3362. async function format: `async functionName(...)`.
  3363. ### imgClient.get(name, file[, options])
  3364. Get an image from the image channel.
  3365. parameters:
  3366. - name {String} image object name with operation style store on OSS
  3367. - [file] {String|WriteStream} file path or WriteStream instance to store the image
  3368. If `file` is null or ignore this parameter, function will return info contains `content` property.
  3369. - [options] {Object} optional parameters
  3370. - [timeout] {Number} the operation timeout
  3371. - [headers] {Object} extra headers, detail see [RFC 2616](http://www.w3.org/Protocols/rfc2616/rfc2616.html)
  3372. - 'If-Modified-Since' object modified after this time will return 200 and object meta,
  3373. otherwise return 304 not modified
  3374. - 'If-Unmodified-Since' object modified before this time will return 200 and object meta,
  3375. otherwise throw PreconditionFailedError
  3376. - 'If-Match' object etag equal this will return 200 and object meta,
  3377. otherwise throw PreconditionFailedError
  3378. - 'If-None-Match' object etag not equal this will return 200 and object meta,
  3379. otherwise return 304 not modified
  3380. Success will return the info contains response.
  3381. object:
  3382. - [content] {Buffer} file content buffer if `file` parameter is null or ignore
  3383. - res {Object} response info, including
  3384. - status {Number} response status
  3385. - headers {Object} response headers
  3386. - size {Number} response size
  3387. - rt {Number} request total use time (ms)
  3388. If object not exists, will throw NoSuchKeyError.
  3389. example:
  3390. - Get an exists image with a style and store it to the local file
  3391. ```js
  3392. const imagepath = '/home/ossdemo/demo.jpg';
  3393. await imgClient.get('ossdemo/demo.jpg@200w_200h', filepath);
  3394. ```
  3395. \_ Store image to a writestream
  3396. ```js
  3397. await imgClient.get('ossdemo/demo.jpg@200w_200h', somestream);
  3398. ```
  3399. - Get an image content buffer
  3400. ```js
  3401. const result = await imgClient.get('ossdemo/demo.jpg@200w_200h');
  3402. console.log(Buffer.isBuffer(result.content));
  3403. ```
  3404. - Get a not exists object or a not image object
  3405. ```js
  3406. const imagepath = '/home/ossdemo/demo.jpg';
  3407. await imgClient.get('ossdemo/not-exists-demo.jpg@200w_200h', filepath);
  3408. // will throw NoSuchKeyError
  3409. ```
  3410. ### imgClient.getStream(name[, options])
  3411. Get an image read stream.
  3412. parameters:
  3413. - name {String} image object name with operation style store on OSS
  3414. - [options] {Object} optional parameters
  3415. - [timeout] {Number} the operation timeout
  3416. - [headers] {Object} extra headers
  3417. - 'If-Modified-Since' object modified after this time will return 200 and object meta,
  3418. otherwise return 304 not modified
  3419. - 'If-Unmodified-Since' object modified before this time will return 200 and object meta,
  3420. otherwise throw PreconditionFailedError
  3421. - 'If-Match' object etag equal this will return 200 and object meta,
  3422. otherwise throw PreconditionFailedError
  3423. - 'If-None-Match' object etag not equal this will return 200 and object meta,
  3424. otherwise return 304 not modified
  3425. Success will return the stream instance and response info.
  3426. object:
  3427. - stream {ReadStream} readable stream instance. If response status is not `200`, stream will be `null`.
  3428. - res {Object} response info, including
  3429. - status {Number} response status
  3430. - headers {Object} response headers
  3431. - size {Number} response size
  3432. - rt {Number} request total use time (ms)
  3433. If object not exists, will throw NoSuchKeyError.
  3434. example:
  3435. - Get an exists image object stream
  3436. ```js
  3437. const result = await imgClient.getStream('ossdemo/demo.jpg@200w_200h');
  3438. result.stream.pipe(fs.createWriteStream('some demo.jpg'));
  3439. ```
  3440. ### imgClient.getExif(name[, options])
  3441. Get a image exif info by image object name from the image channel.
  3442. parameters:
  3443. - name {String} image object name
  3444. - [options] {Object} optional parameters
  3445. - [timeout] {Number} the operation timeout
  3446. Success will return the info contains response.
  3447. object:
  3448. - res {Object} response info, including
  3449. - status {Number} response status
  3450. - headers {Object} response headers
  3451. - size {Number} response size
  3452. - rt {Number} request total use time (ms)
  3453. - data {Object} image exif object
  3454. If object don't have exif, will throw 400 BadRequest.
  3455. example:
  3456. ```js
  3457. const result = await imgClient.getExif('demo.jpg');
  3458. // resut:
  3459. // {
  3460. // res: {
  3461. // status: 200,
  3462. // statusCode: 200,
  3463. // headers: {
  3464. // server: "Tengine",
  3465. // content - type: "application/json",
  3466. // content - length: "148",
  3467. // connection: "keep-alive",
  3468. // date: "Tue, 31 Mar 2015 11:06:32 GMT",
  3469. // "last-modified": "Mon, 30 Mar 2015 10:46:35 GMT"
  3470. // },
  3471. // size: 148,
  3472. // aborted: false,
  3473. // rt: 461,
  3474. // keepAliveSocket: false
  3475. // },
  3476. // data: {
  3477. // FileSize: 343683,
  3478. // ImageHeight: 1200,
  3479. // ImageWidth: 1600,
  3480. // Orientation: 1
  3481. // }
  3482. // }
  3483. ```
  3484. ### imgClient.getInfo(name[, options])
  3485. Get a image info and exif info by image object name from the image channel.
  3486. parameters:
  3487. - name {String} image object name
  3488. - [options] {Object} optional parameters
  3489. - [timeout] {Number} the operation timeout
  3490. Success will return the info contains response.
  3491. object:
  3492. - res {Object} response info, including
  3493. - status {Number} response status
  3494. - headers {Object} response headers
  3495. - size {Number} response size
  3496. - rt {Number} request total use time (ms)
  3497. - data {Object} image exif object
  3498. example:
  3499. ```js
  3500. const result = await imgClient.getInfo('demo.jpg');
  3501. // resut:
  3502. // {
  3503. // res: {
  3504. // status: 200,
  3505. // statusCode: 200,
  3506. // headers: {
  3507. // server: "Tengine",
  3508. // content - type: "application/json",
  3509. // content - length: "148",
  3510. // connection: "keep-alive",
  3511. // date: "Tue, 31 Mar 2015 11:06:32 GMT",
  3512. // "last-modified": "Mon, 30 Mar 2015 10:46:35 GMT"
  3513. // },
  3514. // size: 148,
  3515. // aborted: false,
  3516. // rt: 461,
  3517. // keepAliveSocket: false
  3518. // },
  3519. // data: {
  3520. // FileSize: 343683,
  3521. // Format: "jpg",
  3522. // ImageHeight: 1200,
  3523. // ImageWidth: 1600,
  3524. // Orientation: 1
  3525. // }
  3526. // }
  3527. ```
  3528. ### imgClient.putStyle(name, style[, options])
  3529. // TODO
  3530. ### imgClient.getStyle(name[, options])
  3531. Get a style by name from the image channel.
  3532. parameters:
  3533. - name {String} image style name
  3534. - [options] {Object} optional parameters
  3535. - [timeout] {Number} the operation timeout
  3536. Success will return the info contains response.
  3537. object:
  3538. - res {Object} response info, including
  3539. - status {Number} response status
  3540. - headers {Object} response headers
  3541. - size {Number} response size
  3542. - rt {Number} request total use time (ms)
  3543. - data {Object} styles object
  3544. - Name {String} style name
  3545. - Content {String} style content
  3546. - CreateTime {String} style create time
  3547. - LastModifyTime {String} style last modify time
  3548. example:
  3549. ```js
  3550. const result = await imgClient.getStyle('400');
  3551. // resut:
  3552. // {
  3553. // res: {
  3554. // status: 200,
  3555. // statusCode: 200,
  3556. // headers: {
  3557. // server: "Tengine",
  3558. // content - type: "application/xml",
  3559. // content - length: "234",
  3560. // connection: "keep-alive",
  3561. // date: "Tue, 31 Mar 2015 10:58:20 GMT"
  3562. // },
  3563. // size: 234,
  3564. // aborted: false,
  3565. // rt: 398,
  3566. // keepAliveSocket: false
  3567. // },
  3568. // data: {
  3569. // Name: "400",
  3570. // Content: "400w_90Q_1x.jpg",
  3571. // CreateTime: "Thu, 19 Mar 2015 08:34:21 GMT",
  3572. // LastModifyTime: "Thu, 19 Mar 2015 08:34:21 GMT"
  3573. // }
  3574. // }
  3575. ```
  3576. ### imgClient.listStyle([options])
  3577. Get all styles from the image channel.
  3578. parameters:
  3579. - [options] {Object} optional parameters
  3580. - [timeout] {Number} the operation timeout
  3581. Success will return the info contains response.
  3582. object:
  3583. - res {Object} response info, including
  3584. - status {Number} response status
  3585. - headers {Object} response headers
  3586. - size {Number} response size
  3587. - rt {Number} request total use time (ms)
  3588. - data {Array} styles array, a style object:
  3589. - Name {String} style name
  3590. - Content {String} style content
  3591. - CreateTime {String} style create time
  3592. - LastModifyTime {String} style last modify time
  3593. example:
  3594. ```js
  3595. const result = await imgClient.listStyle();
  3596. // resut:
  3597. // {
  3598. // res: {
  3599. // status: 200,
  3600. // statusCode: 200,
  3601. // headers: {
  3602. // server: "Tengine",
  3603. // content - type: "application/xml",
  3604. // content - length: "913",
  3605. // connection: "keep-alive",
  3606. // date: "Tue, 31 Mar 2015 10:47:32 GMT"
  3607. // },
  3608. // size: 913,
  3609. // aborted: false,
  3610. // rt: 1911,
  3611. // keepAliveSocket: false
  3612. // },
  3613. // data: [{
  3614. // Name: "200-200",
  3615. // Content: "0e_200w_200h_0c_0i_0o_90Q_1x.jpg",
  3616. // CreateTime: "Thu, 19 Mar 2015 08:28:08 GMT",
  3617. // LastModifyTime: "Thu, 19 Mar 2015 08:28:08 GMT"
  3618. // }, {
  3619. // Name: "800",
  3620. // Content: "800w_90Q_1x.jpg",
  3621. // CreateTime: "Thu, 19 Mar 2015 08:29:15 GMT",
  3622. // LastModifyTime: "Thu, 19 Mar 2015 08:29:15 GMT"
  3623. // }, {
  3624. // Name: "400",
  3625. // Content: "400w_90Q_1x.jpg",
  3626. // CreateTime: "Thu, 19 Mar 2015 08:34:21 GMT",
  3627. // LastModifyTime: "Thu, 19 Mar 2015 08:34:21 GMT"
  3628. // }, {
  3629. // Name: "600",
  3630. // Content: "600w_90Q_1x.jpg",
  3631. // CreateTime: "Thu, 19 Mar 2015 08:35:02 GMT",
  3632. // LastModifyTime: "Thu, 19 Mar 2015 08:35:02 GMT"
  3633. // }]
  3634. // }
  3635. ```
  3636. ### imgClient.deleteStyle(name[, options])
  3637. // TODO
  3638. ### imgClient.signatureUrl(name)
  3639. Create a signature url for directly download.
  3640. parameters:
  3641. - name {String} image object name with operation style store on OSS
  3642. - [options] {Object} optional parameters
  3643. - [expires] {Number} after expires seconds, the url will become invalid, default is `1800`
  3644. - [timeout] {Number} the operation timeout
  3645. Success will return full signature url.
  3646. example:
  3647. ```js
  3648. const url = imgClient.signatureUrl('name');
  3649. ```
  3650. ## Cluster Mode
  3651. Cluster mode now only support object operations.
  3652. ```js
  3653. const Cluster = require('ali-oss').ClusterClient;
  3654. const client = Cluster({
  3655. cluster: [
  3656. {
  3657. host: 'host1',
  3658. accessKeyId: 'id1',
  3659. accessKeySecret: 'secret1'
  3660. },
  3661. {
  3662. host: 'host2',
  3663. accessKeyId: 'id2',
  3664. accessKeySecret: 'secret2'
  3665. }
  3666. ],
  3667. schedule: 'masterSlave' //default is `roundRobin`
  3668. });
  3669. // listen error event to logging error
  3670. client.on('error', function (err) {
  3671. console.error(err.stack);
  3672. });
  3673. // client init ready
  3674. client.ready(function () {
  3675. console.log('cluster client init ready, go ahead!');
  3676. });
  3677. ```
  3678. ### Get Methods
  3679. Will choose an alive client by schedule(`masterSlave` or `roundRobin`).
  3680. - `client.get()`
  3681. - `client.head()`
  3682. - `client.getStream()`
  3683. - `client.list()`
  3684. - `client.signatureUrl()`
  3685. - `client.chooseAvailable()` - choose an available client by schedule.
  3686. - `client.getACL()`
  3687. ### Put Methods
  3688. Will put to all clients.
  3689. - `client.put()`
  3690. - `client.putStream()`
  3691. - `client.delete()`
  3692. - `client.deleteMulti()`
  3693. - `client.copy()`
  3694. - `client.putMeta()`
  3695. - `client.putACL()`
  3696. - `client.restore()`
  3697. ## Known Errors
  3698. Each error return by OSS server will contains these properties:
  3699. - name {String} error name
  3700. - message {String} error message
  3701. - requestId {String} uuid for this request, if you meet some unhandled problem,
  3702. you can send this request id to OSS engineer to find out what's happend.
  3703. - hostId {String} OSS cluster name for this request
  3704. ### ResponseTimeoutError
  3705. The default timeout is 60 seconds. Please set the timeout as needed. The timeout unit is milliseconds.
  3706. ```javascript
  3707. client.get('example.txt', { timeout: 60000 * 2 });
  3708. client.get('example.txt', { headers: { Range: `bytes=0-${1024 * 1024 * 100}` } }); // Download the first 100MB
  3709. ```
  3710. ### ConnectionTimeoutError
  3711. The network link timed out. Please check the network status. If there is no problem with the network, please reduce the partSize or increase the timeout.
  3712. ```javascript
  3713. const client = new OSS({ ak, sk, retryMax: 10 });
  3714. client.multipartUpload('example.txt', { timeout: 60000 * 2 });
  3715. client.multipartUpload('example.txt', { partSize: 1024 * 512 }); // partSize 512KB
  3716. ```
  3717. ### The following table lists the OSS error codes:
  3718. [More code info](https://help.aliyun.com/knowledge_detail/32005.html)
  3719. | name | code | status | message | message in Chinese |
  3720. | ---------------------------------------- | ----------------------------------- | ------ | ------------------------------------------------ | -------------------------------------- |
  3721. | AccessDeniedError | AccessDenied | 403 | Access Denied | 拒绝访问 |
  3722. | BucketAlreadyExistsError | BucketAlreadyExists | 409 | Bucket already exists | Bucket 已经存在 |
  3723. | BucketNotEmptyError | BucketNotEmpty | 409 | Bucket is not empty | Bucket 不为空 |
  3724. | RestoreAlreadyInProgressError | RestoreAlreadyInProgress | 409 | The restore operation is in progress. | restore 操作正在进行中 |
  3725. | OperationNotSupportedError | OperationNotSupported | 400 | The operation is not supported for this resource | 该资源暂不支持restore操作 |
  3726. | EntityTooLargeError | EntityTooLarge | 400 | Entity too large | 实体过大 |
  3727. | EntityTooSmallError | EntityTooSmall | 400 | Entity too small | 实体过小 |
  3728. | FileGroupTooLargeError | FileGroupTooLarge | 400 | File group too large | 文件组过大 |
  3729. | InvalidLinkNameError | InvalidLinkName | 400 | Link name can't be the same as the object name | Object Link 与指向的 Object 同名 |
  3730. | LinkPartNotExistError | LinkPartNotExist | 400 | Can't link to not exists object | Object Link 中指向的 Object 不存在 |
  3731. | ObjectLinkTooLargeError | ObjectLinkTooLarge | 400 | Too many links to this object | Object Link 中 Object 个数过多 |
  3732. | FieldItemTooLongError | FieldItemTooLong | 400 | Post form fields items too large | Post 请求中表单域过大 |
  3733. | FilePartInterityError | FilePartInterity | 400 | File part has changed | 文件 Part 已改变 |
  3734. | FilePartNotExistError | FilePartNotExist | 400 | File part not exists | 文件 Part 不存在 |
  3735. | FilePartStaleError | FilePartStale | 400 | File part stale | 文件 Part 过时 |
  3736. | IncorrectNumberOfFilesInPOSTRequestError | IncorrectNumberOfFilesInPOSTRequest | 400 | Post request contains invalid number of files | Post 请求中文件个数非法 |
  3737. | InvalidArgumentError | InvalidArgument | 400 | Invalid format argument | 参数格式错误 |
  3738. | InvalidAccessKeyIdError | InvalidAccessKeyId | 400 | Access key id not exists | Access Key ID 不存在 |
  3739. | InvalidBucketNameError | InvalidBucketName | 400 | Invalid bucket name | 无效的 Bucket 名字 |
  3740. | InvalidDigestError | InvalidDigest | 400 | Invalid digest | 无效的摘要 |
  3741. | InvalidEncryptionAlgorithmError | InvalidEncryptionAlgorithm | 400 | Invalid encryption algorithm | 指定的熵编码加密算法错误 |
  3742. | InvalidObjectNameError | InvalidObjectName | 400 | Invalid object name | 无效的 Object 名字 |
  3743. | InvalidPartError | InvalidPart | 400 | Invalid part | 无效的 Part |
  3744. | InvalidPartOrderError | InvalidPartOrder | 400 | Invalid part order | 无效的 part 顺序 |
  3745. | InvalidPolicyDocumentError | InvalidPolicyDocument | 400 | Invalid policy document | 无效的 Policy 文档 |
  3746. | InvalidTargetBucketForLoggingError | InvalidTargetBucketForLogging | 400 | Invalid bucket on logging operation | Logging 操作中有无效的目标 bucket |
  3747. | InternalError | Internal | 500 | OSS server internal error | OSS 内部发生错误 |
  3748. | MalformedXMLError | MalformedXML | 400 | Malformed XML format | XML 格式非法 |
  3749. | MalformedPOSTRequestError | MalformedPOSTRequest | 400 | Invalid post body format | Post 请求的 body 格式非法 |
  3750. | MaxPOSTPreDataLengthExceededError | MaxPOSTPreDataLengthExceeded | 400 | Post extra data too large | Post 请求上传文件内容之外的 body 过大 |
  3751. | MethodNotAllowedError | MethodNotAllowed | 405 | Not allowed method | 不支持的方法 |
  3752. | MissingArgumentError | MissingArgument | 411 | Missing argument | 缺少参数 |
  3753. | MissingContentLengthError | MissingContentLength | 411 | Missing `Content-Length` header | 缺少内容长度 |
  3754. | NoSuchBucketError | NoSuchBucket | 404 | Bucket not exists | Bucket 不存在 |
  3755. | NoSuchKeyError | NoSuchKey | 404 | Object not exists | 文件不存在 |
  3756. | NoSuchUploadError | NoSuchUpload | 404 | Multipart upload id not exists | Multipart Upload ID 不存在 |
  3757. | NotImplementedError | NotImplemented | 501 | Not implemented | 无法处理的方法 |
  3758. | PreconditionFailedError | PreconditionFailed | 412 | Pre condition failed | 预处理错误 |
  3759. | RequestTimeTooSkewedError | RequestTimeTooSkewed | 403 | Request time exceeds 15 minutes to server time | 发起请求的时间和服务器时间超出 15 分钟 |
  3760. | RequestTimeoutError | RequestTimeout | 400 | Request timeout | 请求超时 |
  3761. | RequestIsNotMultiPartContentError | RequestIsNotMultiPartContent | 400 | Invalid post content-type | Post 请求 content-type 非法 |
  3762. | SignatureDoesNotMatchError | SignatureDoesNotMatch | 403 | Invalid signature | 签名错误 |
  3763. | TooManyBucketsError | TooManyBuckets | 400 | Too many buckets on this user | 用户的 Bucket 数目超过限制 |
  3764. | RequestError | RequestError | -1 | network error | 网络出现中断或异常 |
  3765. | ConnectionTimeoutError | ConnectionTimeoutError | -2 | request connect timeout | 请求连接超时 |
  3766. | SecurityTokenExpiredError | SecurityTokenExpired | 403 | sts Security Token Expired | sts Security Token 超时失效 |
  3767. [generator]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function*
  3768. [oss-sts]: https://help.aliyun.com/document_detail/oss/practice/ram_guide.html
  3769. [browser-sample]: https://github.com/rockuw/oss-in-browser
  3770. [oss-multipart]: https://help.aliyun.com/document_detail/31992.html
  3771. [disabled-browser-headers]: https://www.w3.org/TR/XMLHttpRequest/#the-setrequestheader%28%29-method