Skip to content

Commit

Permalink
Merge pull request #429 from winddies/sdk-bug
Browse files Browse the repository at this point in the history
修复创建文件上传地址中的类型错误
  • Loading branch information
lzfee0227 authored Oct 23, 2019
2 parents c0f5845 + 3243318 commit adaf292
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 25 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ qiniu.compressImage(file, options).then(data => {
* config.disableStatisticsReport: 是否禁用日志报告,为布尔值,默认为 `false`
* config.uphost: 上传 `host`,类型为 `string`, 如果设定该参数则优先使用该参数作为上传地址,默认为 `null`
* config.region: 选择上传域名区域;当为 `null``undefined` 时,自动分析上传域名区域。
* config.retryCount: 上传自动重试次数(整体重试次数,而不是某个分片的重试次数);默认 3 次(即上传失败后最多重试两次)**目前仅在上传过程中产生 `599` 内部错误时生效****但是未来很可能会扩展为支持更多的情况**
* config.retryCount: 上传自动重试次数(整体重试次数,而不是某个分片的重试次数);默认 3 次(即上传失败后最多重试两次)。
* config.concurrentRequestLimit: 分片上传的并发请求量,`number`,默认为3;因为浏览器本身也会限制最大并发量,所以最大并发量与浏览器有关。
* config.checkByMD5: 是否开启 MD5 校验,为布尔值;在断点续传时,开启 MD5 校验会将已上传的分片与当前分片进行 MD5 值比对,若不一致,则重传该分片,避免使用错误的分片。读取分片内容并计算 MD5 需要花费一定的时间,因此会稍微增加断点续传时的耗时,默认为 false,不开启。
* config.forceDirect: 是否上传全部采用直传方式,为布尔值;为 `true` 时则上传方式全部为直传 form 方式,禁用断点续传,默认 `false`
Expand All @@ -201,7 +201,7 @@ qiniu.compressImage(file, options).then(data => {
```

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

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "qiniu-js",
"jsName": "qiniu",
"version": "2.5.4",
"version": "2.5.5",
"private": false,
"description": "Javascript SDK for Qiniu Resource (Cloud) Storage AP",
"main": "dist/qiniu.min.js",
Expand Down
18 changes: 7 additions & 11 deletions src/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
setLocalFileInfo,
removeLocalFileInfo,
getLocalFileInfo,
findMimeType,
isContainFileMimeType,
sum,
getDomainFromUrl,
getPortFromUrl,
Expand Down Expand Up @@ -64,15 +64,11 @@ export class UploadManager {
if (!this.putExtra.fname) {
this.putExtra.fname = this.file.name;
}
if (this.putExtra.mimeType && this.putExtra.mimeType.length) {
var compareMimeType = findMimeType(this.file.type, this.putExtra.mimeType);
if (compareMimeType == null || compareMimeType == undefined) {
let err = new Error("file type doesn't match with what you specify");
this.onError(err);
return;
} else {
this.putExtra.mimeType = [compareMimeType];
}
if (this.putExtra.mimeType && this.putExtra.mimeType.length
&& !isContainFileMimeType(this.file.type, this.putExtra.mimeType)) {
let err = new Error("file type doesn't match with what you specify");
this.onError(err);
return;
}
let upload = getUploadUrl(this.config, this.token).then(res => {
this.uploadUrl = res;
Expand Down Expand Up @@ -255,7 +251,7 @@ export class UploadManager {

let requestUrL = createMkFileUrl(
this.uploadUrl,
this.file.size,
this.file,
this.key,
putExtra
);
Expand Down
16 changes: 5 additions & 11 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,13 @@ export function getResumeUploadedSize(file) {
}

// 构造file上传url
export function createMkFileUrl(url, size, key, putExtra) {
let requestUrl = url + "/mkfile/" + size;
export function createMkFileUrl(url, file, key, putExtra) {
let requestUrl = url + "/mkfile/" + file.size;
if (key != null) {
requestUrl += "/key/" + urlSafeBase64Encode(key);
}
if (putExtra.mimeType) {
requestUrl += "/mimeType/" + urlSafeBase64Encode(putExtra.mimeType);
requestUrl += "/mimeType/" + urlSafeBase64Encode(file.type);
}
let fname = putExtra.fname;
if (fname) {
Expand Down Expand Up @@ -264,14 +264,8 @@ function getUpHosts(token) {
}
}

export function findMimeType(fileType, mimeType) {
var rtType = null;
mimeType.forEach(elem => {
if(fileType == elem){
rtType = fileType;
}
});
return rtType;
export function isContainFileMimeType(fileType, mimeType) {
return mimeType.indexOf(fileType) > -1;
}

export function createObjectURL(file) {
Expand Down

0 comments on commit adaf292

Please sign in to comment.