Skip to content

Commit adaf292

Browse files
authored
Merge pull request #429 from winddies/sdk-bug
修复创建文件上传地址中的类型错误
2 parents c0f5845 + 3243318 commit adaf292

File tree

4 files changed

+15
-25
lines changed

4 files changed

+15
-25
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ qiniu.compressImage(file, options).then(data => {
185185
* config.disableStatisticsReport: 是否禁用日志报告,为布尔值,默认为 `false`
186186
* config.uphost: 上传 `host`,类型为 `string`, 如果设定该参数则优先使用该参数作为上传地址,默认为 `null`
187187
* config.region: 选择上传域名区域;当为 `null``undefined` 时,自动分析上传域名区域。
188-
* config.retryCount: 上传自动重试次数(整体重试次数,而不是某个分片的重试次数);默认 3 次(即上传失败后最多重试两次)**目前仅在上传过程中产生 `599` 内部错误时生效****但是未来很可能会扩展为支持更多的情况**
188+
* config.retryCount: 上传自动重试次数(整体重试次数,而不是某个分片的重试次数);默认 3 次(即上传失败后最多重试两次)。
189189
* config.concurrentRequestLimit: 分片上传的并发请求量,`number`,默认为3;因为浏览器本身也会限制最大并发量,所以最大并发量与浏览器有关。
190190
* config.checkByMD5: 是否开启 MD5 校验,为布尔值;在断点续传时,开启 MD5 校验会将已上传的分片与当前分片进行 MD5 值比对,若不一致,则重传该分片,避免使用错误的分片。读取分片内容并计算 MD5 需要花费一定的时间,因此会稍微增加断点续传时的耗时,默认为 false,不开启。
191191
* config.forceDirect: 是否上传全部采用直传方式,为布尔值;为 `true` 时则上传方式全部为直传 form 方式,禁用断点续传,默认 `false`
@@ -201,7 +201,7 @@ qiniu.compressImage(file, options).then(data => {
201201
```
202202

203203
* fname: `string`,文件原文件名
204-
* params: `object`,用来放置自定义变量
204+
* params: `object`,用来放置自定义变量,自定义变量格式请参考[文档](https://developer.qiniu.com/kodo/manual/1235/vars)
205205
* mimeType: `null || array`,用来限制上传文件类型,为 `null` 时表示不对文件类型限制;限制类型放到数组里:
206206
`["image/png", "image/jpeg", "image/gif"]`
207207

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "qiniu-js",
33
"jsName": "qiniu",
4-
"version": "2.5.4",
4+
"version": "2.5.5",
55
"private": false,
66
"description": "Javascript SDK for Qiniu Resource (Cloud) Storage AP",
77
"main": "dist/qiniu.min.js",

src/upload.js

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
setLocalFileInfo,
66
removeLocalFileInfo,
77
getLocalFileInfo,
8-
findMimeType,
8+
isContainFileMimeType,
99
sum,
1010
getDomainFromUrl,
1111
getPortFromUrl,
@@ -64,15 +64,11 @@ export class UploadManager {
6464
if (!this.putExtra.fname) {
6565
this.putExtra.fname = this.file.name;
6666
}
67-
if (this.putExtra.mimeType && this.putExtra.mimeType.length) {
68-
var compareMimeType = findMimeType(this.file.type, this.putExtra.mimeType);
69-
if (compareMimeType == null || compareMimeType == undefined) {
70-
let err = new Error("file type doesn't match with what you specify");
71-
this.onError(err);
72-
return;
73-
} else {
74-
this.putExtra.mimeType = [compareMimeType];
75-
}
67+
if (this.putExtra.mimeType && this.putExtra.mimeType.length
68+
&& !isContainFileMimeType(this.file.type, this.putExtra.mimeType)) {
69+
let err = new Error("file type doesn't match with what you specify");
70+
this.onError(err);
71+
return;
7672
}
7773
let upload = getUploadUrl(this.config, this.token).then(res => {
7874
this.uploadUrl = res;
@@ -255,7 +251,7 @@ export class UploadManager {
255251

256252
let requestUrL = createMkFileUrl(
257253
this.uploadUrl,
258-
this.file.size,
254+
this.file,
259255
this.key,
260256
putExtra
261257
);

src/utils.js

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,13 @@ export function getResumeUploadedSize(file) {
8080
}
8181

8282
// 构造file上传url
83-
export function createMkFileUrl(url, size, key, putExtra) {
84-
let requestUrl = url + "/mkfile/" + size;
83+
export function createMkFileUrl(url, file, key, putExtra) {
84+
let requestUrl = url + "/mkfile/" + file.size;
8585
if (key != null) {
8686
requestUrl += "/key/" + urlSafeBase64Encode(key);
8787
}
8888
if (putExtra.mimeType) {
89-
requestUrl += "/mimeType/" + urlSafeBase64Encode(putExtra.mimeType);
89+
requestUrl += "/mimeType/" + urlSafeBase64Encode(file.type);
9090
}
9191
let fname = putExtra.fname;
9292
if (fname) {
@@ -264,14 +264,8 @@ function getUpHosts(token) {
264264
}
265265
}
266266

267-
export function findMimeType(fileType, mimeType) {
268-
var rtType = null;
269-
mimeType.forEach(elem => {
270-
if(fileType == elem){
271-
rtType = fileType;
272-
}
273-
});
274-
return rtType;
267+
export function isContainFileMimeType(fileType, mimeType) {
268+
return mimeType.indexOf(fileType) > -1;
275269
}
276270

277271
export function createObjectURL(file) {

0 commit comments

Comments
 (0)