Skip to content

Commit c1e4fe5

Browse files
author
YangSen-qn
committed
fix: invalid part size
1 parent d746363 commit c1e4fe5

File tree

11 files changed

+66
-61
lines changed

11 files changed

+66
-61
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ qiniu.compressImage(file, options).then(data => {
224224
* config.region: 选择上传域名区域;当为 `null``undefined` 时,自动分析上传域名区域,当指定了 `uphost` 时,此设置项无效。
225225
* config.retryCount: 上传自动重试次数(整体重试次数,而不是某个分片的重试次数);默认 3 次(即上传失败后最多重试两次)。
226226
* config.concurrentRequestLimit: 分片上传的并发请求量,`number`,默认为3;因为浏览器本身也会限制最大并发量,所以最大并发量与浏览器有关。
227-
* config.checkByServer: 是否开启服务端文件签名校验,为布尔值;开启后在文件上传时会计算本地的文件签名,服务端会根据本地的签名与接收到的数据的签名进行比对,如果不相同、则说明文件可能存在问题,此时会返回错误(`code`: 406),默认为 `false`,不开启。
227+
* config.checkByServer: 是否开启服务端文件签名校验,为布尔值;开启后在文件上传时会计算本地的文件签名,服务端会根据本地的签名与接收到的数据的签名进行比对,如果不相同、则说明文件可能存在问题,此时会返回错误(`code`: 406),默认为 `true`,不开启。
228228
* config.checkByMD5: 是否开启 `MD5` 校验,为布尔值;在断点续传时,开启 `MD5` 校验会将已上传的分片与当前分片进行 `MD5` 值比对,若不一致,则重传该分片,避免使用错误的分片。读取分片内容并计算 `MD5` 需要花费一定的时间,因此会稍微增加断点续传时的耗时,默认为 `false`,不开启。
229229
* config.forceDirect: 是否上传全部采用直传方式,为布尔值;为 `true` 时则上传方式全部为直传 form 方式,禁用断点续传,默认 `false`
230230
* config.chunkSize: `number`,分片上传时每片的大小,必须为正整数,单位为 `MB`,且最大不能超过 1024,默认值 4。因为 chunk 数最大 10000,所以如果文件以你所设的 `chunkSize` 进行分片并且 chunk 数超过 10000,我们会把你所设的 `chunkSize` 扩大二倍,如果仍不符合则继续扩大,直到符合条件。

site/.eslintrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"root": true,
23
"extends": [
34
"@qiniu"
45
]

site/package.json

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,17 @@
44
"version": "1.0.0",
55
"main": "index.js",
66
"scripts": {
7-
"dev": "webpack serve --mode development --inline --hot --open",
8-
"start": "webpack serve --mode development",
9-
"build": "webpack --mode development",
7+
"dev": "NODE_OPTIONS=--openssl-legacy-provider webpack serve --mode development --inline --hot --open",
8+
"start": "NODE_OPTIONS=--openssl-legacy-provider webpack serve --mode development",
9+
"build": "NODE_OPTIONS=--openssl-legacy-provider webpack --mode development",
1010
"lint": "eslint --ext .tsx,.ts src/"
1111
},
1212
"license": "MIT",
1313
"devDependencies": {
1414
"@qiniu/eslint-config": "0.0.6-beta.7",
15-
"@types/react": "17",
16-
"@types/react-dom": "17",
15+
"@types/create-hmac": "^1.1.3",
16+
"@types/react": "^18.3.0",
17+
"@types/react-dom": "^18.3.0",
1718
"@typescript-eslint/eslint-plugin": "~4.10.0",
1819
"buffer": "^6.0.3",
1920
"css-loader": "^5.2.4",
@@ -42,7 +43,7 @@
4243
"byte-size": "^7.0.1",
4344
"create-hmac": "^1.1.7",
4445
"js-base64": "^3.7.2",
45-
"react": "^17.0.2",
46-
"react-dom": "^17.0.2"
46+
"react": "^18.3.1",
47+
"react-dom": "^18.3.1"
4748
}
4849
}

site/src/components/App/index.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { Queue } from '../Queue'
44
import { Layout } from '../Layout'
55
import { Settings } from '../Settings'
66
import { SelectFile, UniqueFile } from '../SelectFile'
7-
import { getChunks } from '../../../../src/utils/helper'
87

98
import settingIcon from '../Settings/assets/setting.svg'
109
import classnames from './style.less'

site/src/components/Queue/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as React from 'react'
2+
23
import type { UniqueFile } from '../SelectFile'
34

45
import { Item } from './item'

site/src/components/Settings/index.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as React from 'react'
2+
23
import * as utils from '../../utils'
34

45
import { Input } from '../Input'
@@ -24,11 +25,11 @@ export function Settings(props: IProps) {
2425
})
2526
}, [assessKey, secretKey, bucketName, deadline, uphost])
2627

27-
React.useEffect(()=> {
28+
React.useEffect(() => {
2829
if (deadline > 0) return
2930
// 基于当前时间加上 3600s
3031
setDeadline(Math.floor(Date.now() / 1000) + 3600)
31-
},[deadline])
32+
}, [deadline])
3233

3334
return (
3435
<div className={classnames.settings}>

site/src/upload.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,10 @@ export enum Status {
1313

1414
// 上传逻辑封装
1515
export function useUpload(file: File) {
16-
const defaultToken = "dxVQk8gyk3WswArbNhdKIwmwibJ9nFsQhMNUmtIM:SvCtd4GFhiKQ9mMKvTz7Eu5uMss=:eyJzY29wZSI6InRlc3QteXMiLCJkZWFkbGluZSI6MzUwMDM3NDE5OH0="
1716
const startTimeRef = React.useRef<number | null>(null)
1817
const [state, setState] = React.useState<Status | null>(null)
1918
const [error, setError] = React.useState<Error | null>(null)
20-
const [token, setToken] = React.useState<string | null>(defaultToken)
19+
const [token, setToken] = React.useState<string | null>(null)
2120
const [speedPeak, setSpeedPeak] = React.useState<number | null>(null)
2221
const [completeInfo, setCompleteInfo] = React.useState<any | null>(null)
2322
const [progress, setProgress] = React.useState<UploadProgress | null>(null)
@@ -75,8 +74,12 @@ export function useUpload(file: File) {
7574

7675
// 线上应该使用服务端生成 token
7776
if (token != null) return
78-
setToken(generateUploadToken({ assessKey, secretKey, bucketName, deadline }))
79-
}, [file])
77+
78+
// 确保所有必需的参数都存在后再调用 generateUploadToken
79+
if (assessKey && secretKey && bucketName && deadline) {
80+
setToken(generateUploadToken({ assessKey, secretKey, bucketName, deadline }))
81+
}
82+
}, [file, token])
8083

8184
// 创建上传任务
8285
React.useEffect(() => {
@@ -92,11 +95,12 @@ export function useUpload(file: File) {
9295
metadata: {
9396
'x-qn-meta-test': 'tt',
9497
'x-qn-meta-test1': '222',
95-
'x-qn-meta-test2': '333',
98+
'x-qn-meta-test2': '333'
9699
}
97100
},
98101
{
99-
checkByMD5: true,
102+
// checkByMD5: true,
103+
checkByServer: true,
100104
chunkSize: 2,
101105
concurrentRequestLimit: 3,
102106
debugLogLevel: 'INFO',

site/yarn.lock

Lines changed: 34 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,13 @@
7272
"@typescript-eslint/parser" "~4.10.0"
7373
eslint-config-airbnb "~18.2.0"
7474

75+
"@types/create-hmac@^1.1.3":
76+
version "1.1.3"
77+
resolved "https://mirrors.cloud.tencent.com/npm/@types/create-hmac/-/create-hmac-1.1.3.tgz#fba2fe41fb98d37b76da2ca5a7158dc7408727dc"
78+
integrity sha512-oDDSoBrAfdEPQuBpQp14y/ygUVU1IC6gq8Arm8IPP8TRC11AnLLYmpE3VvNUhPK/Ax3USGDjdE1Sc1LCIpf0NQ==
79+
dependencies:
80+
"@types/node" "*"
81+
7582
"@types/eslint-scope@^3.7.0":
7683
version "3.7.0"
7784
resolved "https://registry.yarnpkg.com/@types/eslint-scope/-/eslint-scope-3.7.0.tgz#4792816e31119ebd506902a482caec4951fabd86"
@@ -127,29 +134,23 @@
127134
integrity sha512-8/bnjSZD86ZfpBsDlCIkNXIvm+h6wi9g7IqL+kmFkQ+Wvu3JrasgLElfiPgoo8V8vVfnEi0QVS12gbl94h9YsQ==
128135

129136
"@types/prop-types@*":
130-
version "15.7.15"
131-
resolved "https://mirrors.cloud.tencent.com/npm/@types/prop-types/-/prop-types-15.7.15.tgz#e6e5a86d602beaca71ce5163fadf5f95d70931c7"
132-
integrity sha512-F6bEyamV9jKGAFBEmlQnesRPGOQqS2+Uwi0Em15xenOxHaf2hv6L8YCVn3rPdPJOiJfPiCnLIRyvwVaqMY3MIw==
137+
version "15.7.3"
138+
resolved "https://registry.yarnpkg.com/@types/prop-types/-/prop-types-15.7.3.tgz#2ab0d5da2e5815f94b0b9d4b95d1e5f243ab2ca7"
139+
integrity sha512-KfRL3PuHmqQLOG+2tGpRO26Ctg+Cq1E01D2DMriKEATHgWLfeNDmq9e29Q9WIky0dQ3NPkd1mzYH8Lm936Z9qw==
133140

134-
"@types/react-dom@17":
135-
version "17.0.26"
136-
resolved "https://mirrors.cloud.tencent.com/npm/@types/react-dom/-/react-dom-17.0.26.tgz#fa7891ba70fd39ddbaa7e85b6ff9175bb546bc1b"
137-
integrity sha512-Z+2VcYXJwOqQ79HreLU/1fyQ88eXSSFh6I3JdrEHQIfYSI0kCQpTGvOrbE6jFGGYXKsHuwY9tBa/w5Uo6KzrEg==
141+
"@types/react-dom@^18.3.0":
142+
version "18.3.7"
143+
resolved "https://mirrors.cloud.tencent.com/npm/@types/react-dom/-/react-dom-18.3.7.tgz#b89ddf2cd83b4feafcc4e2ea41afdfb95a0d194f"
144+
integrity sha512-MEe3UeoENYVFXzoXEWsvcpg6ZvlrFNlOQ7EOsvhI3CfAXwzPfO8Qwuxd40nepsYKqyyVQnTdEfv68q91yLcKrQ==
138145

139-
"@types/react@17":
140-
version "17.0.87"
141-
resolved "https://mirrors.cloud.tencent.com/npm/@types/react/-/react-17.0.87.tgz#998a5e146fbea449986d95a794c0aff47f12b6e6"
142-
integrity sha512-wpg9AbtJ6agjA+BKYmhG6dRWEU/2DHYwMzCaBzsz137ft6IyuqZ5fI4ic1DWL4DrI03Zy78IyVE6ucrXl0mu4g==
146+
"@types/react@^18.3.0":
147+
version "18.3.23"
148+
resolved "https://mirrors.cloud.tencent.com/npm/@types/react/-/react-18.3.23.tgz#86ae6f6b95a48c418fecdaccc8069e0fbb63696a"
149+
integrity sha512-/LDXMQh55EzZQ0uVAZmKKhfENivEvWz6E+EYzh+/MCjMhNsotd+ZHhBGIjFDTi6+fz0OhQQQLbTgdQIxxCsC0w==
143150
dependencies:
144151
"@types/prop-types" "*"
145-
"@types/scheduler" "^0.16"
146152
csstype "^3.0.2"
147153

148-
"@types/scheduler@^0.16":
149-
version "0.16.8"
150-
resolved "https://mirrors.cloud.tencent.com/npm/@types/scheduler/-/scheduler-0.16.8.tgz#ce5ace04cfeabe7ef87c0091e50752e36707deff"
151-
integrity sha512-WZLiwShhwLRmeV6zH+GkbOFT6Z6VklCItrDioxUnv+u4Ll+8vKeFySoFyK/0ctcRpOmwAicELfmys1sDc/Rw+A==
152-
153154
"@typescript-eslint/eslint-plugin@~4.10.0":
154155
version "4.10.0"
155156
resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-4.10.0.tgz#19ed3baf4bc4232c5a7fcd32eaca75c3a5baf9f3"
@@ -1146,9 +1147,9 @@ cssesc@^3.0.0:
11461147
integrity sha512-/Tb/JcjK111nNScGob5MNtsntNM1aCNUDipB/TkwZFhyDrrE47SOx/18wF2bbjgc3ZzCSKW1T5nt5EbFoAz/Vg==
11471148

11481149
csstype@^3.0.2:
1149-
version "3.1.3"
1150-
resolved "https://mirrors.cloud.tencent.com/npm/csstype/-/csstype-3.1.3.tgz#d80ff294d114fb0e6ac500fbf85b60137d7eff81"
1151-
integrity sha512-M1uQkMl8rQK/szD0LNhtqxIPLpimGm8sOBwU7lLnCpSbTyY3yeU1Vc7l4KT5zT4s/yOxHH5O7tIuuLOCnLADRw==
1150+
version "3.0.8"
1151+
resolved "https://registry.yarnpkg.com/csstype/-/csstype-3.0.8.tgz#d2266a792729fb227cd216fb572f43728e1ad340"
1152+
integrity sha512-jXKhWqXPmlUeoQnF/EhTtTl4C9SnrxSH/jZUih3jmO6lBKr99rP3/+FmrMj4EFpOXzMtXHAZkd3x0E6h6Fgflw==
11521153

11531154
damerau-levenshtein@^1.0.6:
11541155
version "1.0.7"
@@ -3830,27 +3831,25 @@ [email protected]:
38303831
iconv-lite "0.4.24"
38313832
unpipe "1.0.0"
38323833

3833-
react-dom@^17.0.2:
3834-
version "17.0.2"
3835-
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-17.0.2.tgz#ecffb6845e3ad8dbfcdc498f0d0a939736502c23"
3836-
integrity sha512-s4h96KtLDUQlsENhMn1ar8t2bEa+q/YAtj8pPPdIjPDGBDIVNsrD9aXNWqspUe6AzKCIG0C1HZZLqLV7qpOBGA==
3834+
react-dom@^18.3.1:
3835+
version "18.3.1"
3836+
resolved "https://mirrors.cloud.tencent.com/npm/react-dom/-/react-dom-18.3.1.tgz#c2265d79511b57d479b3dd3fdfa51536494c5cb4"
3837+
integrity sha512-5m4nQKp+rZRb09LNH59GM4BxTh9251/ylbKIbpe7TpGxfJ+9kv6BLkLBXIjjspbgbnIBNqlI23tRnTWT0snUIw==
38373838
dependencies:
38383839
loose-envify "^1.1.0"
3839-
object-assign "^4.1.1"
3840-
scheduler "^0.20.2"
3840+
scheduler "^0.23.2"
38413841

38423842
react-is@^16.8.1:
38433843
version "16.13.1"
38443844
resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.13.1.tgz#789729a4dc36de2999dc156dd6c1d9c18cea56a4"
38453845
integrity sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==
38463846

3847-
react@^17.0.2:
3848-
version "17.0.2"
3849-
resolved "https://registry.yarnpkg.com/react/-/react-17.0.2.tgz#d0b5cc516d29eb3eee383f75b62864cfb6800037"
3850-
integrity sha512-gnhPt75i/dq/z3/6q/0asP78D0u592D5L1pd7M8P+dck6Fu/jJeL6iVVK23fptSUZj8Vjf++7wXA8UNclGQcbA==
3847+
react@^18.3.1:
3848+
version "18.3.1"
3849+
resolved "https://mirrors.cloud.tencent.com/npm/react/-/react-18.3.1.tgz#49ab892009c53933625bd16b2533fc754cab2891"
3850+
integrity sha512-wS+hAgJShR0KhEvPJArfuPVN1+Hz1t0Y6n5jLrGQbkb4urgPE/0Rve+1kMB1v/oWgHgm4WIcV+i7F2pTVj+2iQ==
38513851
dependencies:
38523852
loose-envify "^1.1.0"
3853-
object-assign "^4.1.1"
38543853

38553854
read-pkg-up@^2.0.0:
38563855
version "2.0.0"
@@ -4112,13 +4111,12 @@ sax@^1.2.4:
41124111
resolved "https://registry.yarnpkg.com/sax/-/sax-1.2.4.tgz#2816234e2378bddc4e5354fab5caa895df7100d9"
41134112
integrity sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw==
41144113

4115-
scheduler@^0.20.2:
4116-
version "0.20.2"
4117-
resolved "https://registry.yarnpkg.com/scheduler/-/scheduler-0.20.2.tgz#4baee39436e34aa93b4874bddcbf0fe8b8b50e91"
4118-
integrity sha512-2eWfGgAqqWFGqtdMmcL5zCMK1U8KlXv8SQFGglL3CEtd0aDVDWgeF/YoCmvln55m5zSk3J/20hTaSBeSObsQDQ==
4114+
scheduler@^0.23.2:
4115+
version "0.23.2"
4116+
resolved "https://mirrors.cloud.tencent.com/npm/scheduler/-/scheduler-0.23.2.tgz#414ba64a3b282892e944cf2108ecc078d115cdc3"
4117+
integrity sha512-UOShsPwz7NrMUqhR6t0hWjFduvOzbtv7toDH1/hIrfRNIDBnnBWd0CwJTGvTpngVlmwGCdP9/Zl/tVrDqcuYzQ==
41194118
dependencies:
41204119
loose-envify "^1.1.0"
4121-
object-assign "^4.1.1"
41224120

41234121
schema-utils@^1.0.0:
41244122
version "1.0.0"

src/upload/base.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export const DEFAULT_CHUNK_SIZE = 4 // 单位 MB
99

1010
// code 信息地址 https://developer.qiniu.com/kodo/3928/error-responses
1111
export const FREEZE_CODE_LIST = [0, 502, 503, 504, 599] // 将会冻结当前 host 的 code
12-
export const RETRY_CODE_LIST = [...FREEZE_CODE_LIST, 612] // 会进行重试的 code
12+
export const RETRY_CODE_LIST = [...FREEZE_CODE_LIST, 406] // 会进行重试的 code
1313

1414
/** 上传文件的资源信息配置 */
1515
export interface Extra {

src/utils/config.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ describe('test config ', () => {
99
uphost: [],
1010
retryCount: 3,
1111
checkByMD5: false,
12-
checkByServer: false,
12+
checkByServer: true,
1313
forceDirect: false,
1414
useCdnDomain: true,
1515
concurrentRequestLimit: 3,
@@ -24,7 +24,7 @@ describe('test config ', () => {
2424
uphost: [],
2525
retryCount: 3,
2626
checkByMD5: false,
27-
checkByServer: false,
27+
checkByServer: true,
2828
forceDirect: false,
2929
useCdnDomain: true,
3030
concurrentRequestLimit: 3,
@@ -40,7 +40,7 @@ describe('test config ', () => {
4040
uphost: regionUphostMap[region.z0].cdnUphost,
4141
retryCount: 3,
4242
checkByMD5: false,
43-
checkByServer: false,
43+
checkByServer: true,
4444
forceDirect: false,
4545
useCdnDomain: true,
4646
concurrentRequestLimit: 3,
@@ -55,7 +55,7 @@ describe('test config ', () => {
5555
uphost: ['test'],
5656
retryCount: 3,
5757
checkByMD5: false,
58-
checkByServer: false,
58+
checkByServer: true,
5959
forceDirect: false,
6060
useCdnDomain: true,
6161
concurrentRequestLimit: 3,
@@ -71,7 +71,7 @@ describe('test config ', () => {
7171
uphost: ['test'],
7272
retryCount: 3,
7373
checkByMD5: false,
74-
checkByServer: false,
74+
checkByServer: true,
7575
forceDirect: false,
7676
useCdnDomain: true,
7777
concurrentRequestLimit: 3,
@@ -87,7 +87,7 @@ describe('test config ', () => {
8787
uphost: regionUphostMap[region.z0].srcUphost,
8888
retryCount: 3,
8989
checkByMD5: false,
90-
checkByServer: false,
90+
checkByServer: true,
9191
forceDirect: false,
9292
useCdnDomain: false,
9393
concurrentRequestLimit: 3,

0 commit comments

Comments
 (0)