@@ -88,7 +88,7 @@ Qiniu-JavaScript-SDK 的示例 [Demo](http://jssdk-v2.demo.qiniu.io) 中的服
88
88
npm install qiniu-js
89
89
```
90
90
``` Javascript
91
- var qiniu = require (' qiniu-js' )
91
+ const qiniu = require (' qiniu-js' )
92
92
// or
93
93
import * as qiniu from ' qiniu-js'
94
94
```
@@ -109,31 +109,31 @@ Qiniu-JavaScript-SDK 的示例 [Demo](http://jssdk-v2.demo.qiniu.io) 中的服
109
109
110
110
``` JavaScript
111
111
112
- var observable = qiniu .upload (file, key, token, putExtra, config)
112
+ const observable = qiniu .upload (file, key, token, putExtra, config)
113
113
114
- var subscription = observable .subscribe (observer) // 上传开始
114
+ const subscription = observable .subscribe (observer) // 上传开始
115
115
// or
116
- var subscription = observable .subscribe (next, error, complete) // 这样传参形式也可以
116
+ const subscription = observable .subscribe (next, error, complete) // 这样传参形式也可以
117
117
118
118
subscription .unsubscribe () // 上传取消
119
119
```
120
120
图片上传前压缩:
121
121
122
122
``` JavaScript
123
- let options = {
123
+ const options = {
124
124
quality: 0.92 ,
125
125
noCompressIfLarger: true
126
126
// maxWidth: 1000,
127
127
// maxHeight: 618
128
128
}
129
129
qiniu .compressImage (file, options).then (data => {
130
- var observable = qiniu .upload (data .dist , key, token, putExtra, config)
131
- var subscription = observable .subscribe (observer) // 上传开始
130
+ const observable = qiniu .upload (data .dist , key, token, putExtra, config)
131
+ const subscription = observable .subscribe (observer) // 上传开始
132
132
})
133
133
```
134
134
## API Reference Interface
135
135
136
- ### qiniu.upload(file: blob , key: string, token: string, putExtra: object, config: object): observable
136
+ ### qiniu.upload(file: File , key: string, token: string, putExtra: object, config: object): observable
137
137
138
138
* ** observable** : 为一个带有 subscribe 方法的类实例
139
139
@@ -142,7 +142,7 @@ qiniu.compressImage(file, options).then(data => {
142
142
* observer: ` observer ` 为一个 ` object ` ,用来设置上传过程的监听函数,有三个属性 ` next ` 、` error ` 、` complete ` :
143
143
144
144
``` JavaScript
145
- var observer = {
145
+ const observer = {
146
146
next (res ){
147
147
// ...
148
148
},
@@ -169,13 +169,13 @@ qiniu.compressImage(file, options).then(data => {
169
169
170
170
* subscription: 为一个带有 ` unsubscribe` 方法的类实例,通过调用 ` subscription.unsubscribe()` 停止当前文件上传。
171
171
172
- * ** file** : ` Blob ` 对象,上传的文件
172
+ * ** file** : ` File ` 对象,上传的文件
173
173
* ** key** : 文件资源名
174
174
* ** token** : 上传验证信息,前端通过接口请求后端获得
175
175
* ** config** : ` object`
176
176
177
177
` ` ` JavaScript
178
- var config = {
178
+ const config = {
179
179
useCdnDomain: true,
180
180
region: qiniu.region.z2
181
181
};
@@ -193,15 +193,15 @@ qiniu.compressImage(file, options).then(data => {
193
193
* ** putExtra** :
194
194
195
195
` ` ` JavaScript
196
- var putExtra = {
196
+ const putExtra = {
197
197
fname: "",
198
198
params: {},
199
199
mimeType: [] || null
200
200
};
201
201
` ` `
202
202
203
203
* fname: ` string` ,文件原文件名
204
- * params: ` object` ,用来放置自定义变量,自定义变量格式请参考 [文档](https: // developer.qiniu.com/kodo/manual/1235/vars)
204
+ * params: ` object` ,用来放置自定义变量,变量名必须以 ` x: ` 开始,自定义变量格式及说明请参考 [文档](https: // developer.qiniu.com/kodo/manual/1235/vars)
205
205
* mimeType: ` null || array` ,用来限制上传文件类型,为 ` null` 时表示不对文件类型限制;限制类型放到数组里:
206
206
` ["image/png", "image/jpeg", "image/gif"]`
207
207
@@ -215,11 +215,11 @@ qiniu.compressImage(file, options).then(data => {
215
215
* ** putExtra** : 同上
216
216
217
217
` ` ` JavaScript
218
- var requestUrl = qiniu.createMkFileUrl(
219
- uploadUrl,
220
- file.size,
221
- key,
222
- putExtra
218
+ const requestUrl = qiniu.createMkFileUrl(
219
+ uploadUrl,
220
+ file.size,
221
+ key,
222
+ putExtra
223
223
);
224
224
` ` `
225
225
@@ -245,45 +245,45 @@ qiniu.compressImage(file, options).then(data => {
245
245
* ** token** : 后端返回的上传验证信息
246
246
247
247
` ` ` JavaScript
248
- var headers = qiniu.getHeadersForChunkUpload(token)
248
+ const headers = qiniu.getHeadersForChunkUpload(token)
249
249
` ` `
250
250
251
251
### qiniu .getHeadersForMkFile (token: string): object
252
252
253
253
返回 ` object` ,包含用来获得文件创建的头信息,参数为 ` token` 字符串;当分片上传完需要把 ctx 信息传给七牛用来创建文件时,请求需要带该函数返回的头信息
254
254
255
255
` ` ` JavaScript
256
- var headers = qiniu.getHeadersForMkFile(token)
256
+ const headers = qiniu.getHeadersForMkFile(token)
257
257
` ` `
258
258
259
- ### qiniu .getResumeUploadedSize (file: blob ): number
259
+ ### qiniu .getResumeUploadedSize (file: File ): number
260
260
断点续传时返回文件之前已上传的字节数,为 0 代表当前并无该文件的断点信息
261
261
262
262
### qiniu .filterParams (params: object): array
263
263
264
264
返回[[k, v],... ]格式的数组,k 为自定义变量 ` key` 名,v 为自定义变量值,用来提取 ` putExtra.params` 包含的自定义变量
265
265
266
266
` ` ` JavaScript
267
- var customVarList = qiniu.filterParams(putExtra.params)
267
+ const customVarList = qiniu.filterParams(putExtra.params)
268
268
269
- for (var i = 0; i < customVarList.length; i++) {
270
- var k = customVarList[i]
269
+ for (let i = 0; i < customVarList.length; i++) {
270
+ const k = customVarList[i]
271
271
multipart_params_obj[k[0]] = k[1]
272
272
}
273
273
` ` `
274
- ### qiniu .compressImage (file: blob , options: object) : Promise (上传前图片压缩)
274
+ ### qiniu .compressImage (file: File , options: object) : Promise (上传前图片压缩)
275
275
276
276
` ` ` JavaScript
277
- var imgLink = qiniu.compressImage(file, options).then(res => {
277
+ const imgLink = qiniu.compressImage(file, options).then(res => {
278
278
// res : {
279
- // dist: 压缩后输出的 blob 对象,或原始的 file,具体看下面的 options 配置
279
+ // dist: 压缩后输出的 File 对象,或原始的 file,具体看下面的 options 配置
280
280
// width: 压缩后的图片宽度
281
281
// height: 压缩后的图片高度
282
282
// }
283
283
}
284
284
})
285
285
` ` `
286
- * file: 要压缩的源图片,为 ` blob ` 对象,支持 ` image/png` 、` image/jpeg` 、` image/bmp` 、` image/webp` 这几种图片类型
286
+ * file: 要压缩的源图片,为 ` File ` 对象,支持 ` image/png` 、` image/jpeg` 、` image/bmp` 、` image/webp` 这几种图片类型
287
287
* options: ` object`
288
288
* options .quality : ` number` ,图片压缩质量,在图片格式为 ` image/jpeg` 或 ` image/webp` 的情况下生效,其他格式不会生效,可以从 0 到 1 的区间内选择图片的质量。默认值 0.92
289
289
* options .maxWidh : ` number` ,压缩图片的最大宽度值
@@ -299,7 +299,7 @@ qiniu.compressImage(file, options).then(data => {
299
299
300
300
` ` ` JavaScript
301
301
302
- var imgLink = qiniu.watermark({
302
+ const imgLink = qiniu.watermark({
303
303
mode: 1, // 图片水印
304
304
image: 'http://www.b1.qiniudn.com/images/logo-2.png', // 图片水印的Url,mode = 1 时 **必需**
305
305
dissolve: 50, // 透明度,取值范围1-100,非必需,下同
@@ -316,7 +316,7 @@ qiniu.compressImage(file, options).then(data => {
316
316
317
317
// 或者
318
318
319
- var imgLink = qiniu.watermark({
319
+ const imgLink = qiniu.watermark({
320
320
mode: 2, // 文字水印
321
321
text: 'hello world !', // 水印文字,mode = 2 时 **必需**
322
322
dissolve: 50, // 透明度,取值范围1-100,非必需,下同
@@ -336,7 +336,7 @@ qiniu.compressImage(file, options).then(data => {
336
336
返回处理后的图片url
337
337
338
338
` ` ` JavaScript
339
- var imgLink = qiniu.imageView2({
339
+ const imgLink = qiniu.imageView2({
340
340
mode: 3, // 缩略模式,共6种[0-5]
341
341
w: 100, // 具体含义由缩略模式决定
342
342
h: 100, // 具体含义由缩略模式决定
@@ -352,7 +352,7 @@ qiniu.compressImage(file, options).then(data => {
352
352
返回处理后的图片url
353
353
354
354
` ` ` JavaScript
355
- var imgLink = qiniu.imageMogr2({
355
+ const imgLink = qiniu.imageMogr2({
356
356
"auto-orient": true, // 布尔值,是否根据原图EXIF信息自动旋正,便于后续处理,建议放在首位。
357
357
strip: true, // 布尔值,是否去除图片中的元信息
358
358
thumbnail: '1000x1000' // 缩放操作参数
@@ -386,7 +386,7 @@ qiniu.compressImage(file, options).then(data => {
386
386
### qiniu .pipeline (fopArr: array, key: string, domain: string): string
387
387
388
388
` ` ` JavaScript
389
- var fopArr = [{
389
+ const fopArr = [{
390
390
fop: 'watermark', // 指定watermark操作
391
391
mode: 2, // 此参数同watermark函数的参数,下同。
392
392
text: 'hello world !',
@@ -419,7 +419,7 @@ qiniu.compressImage(file, options).then(data => {
419
419
420
420
// fopArr 可以为三种类型'watermark'、'imageMogr2'、'imageView2'中的任意1-3个
421
421
// 例如只对'watermark'、'imageMogr2'进行管道操作,则如下即可
422
- // var fopArr = [{
422
+ // const fopArr = [{
423
423
// fop: 'watermark', // 指定watermark操作
424
424
// mode: 2, // 此参数同watermark函数的参数,下同。
425
425
// text: 'hello world !',
@@ -443,7 +443,7 @@ qiniu.compressImage(file, options).then(data => {
443
443
// blur:'3x5'
444
444
// }];
445
445
446
- var imgLink = qiniu.pipeline(fopArr, key, domain))
446
+ const imgLink = qiniu.pipeline(fopArr, key, domain))
447
447
` ` `
448
448
449
449
fopArr包含的具体管道操作解释见[管道操作](https: // developer.qiniu.com/dora/manual/processing-mechanism)
0 commit comments