| | |
| | | } |
| | | } |
| | | |
| | | getExtraData = file => { |
| | | const param = new FormData() |
| | | param.append('file', file) |
| | | param.append('RootPath', 'Content/images/upload/') |
| | | |
| | | return param |
| | | getExtraData = () => { |
| | | return { |
| | | RootPath: 'Content/images/upload/' |
| | | } |
| | | } |
| | | |
| | | shardupload = (file, shardSize, shardCount, i) => { |
| | | shardupload = (file, shardSize, shardCount, i, fileList) => { |
| | | let start = i * shardSize |
| | | let end = Math.min(file.size, start + shardSize) |
| | | let form = new FormData() |
| | | |
| | | form.append('data', file.slice(start, end)) //slice方法用于切出文件的一部分 |
| | | form.append('file', file.slice(start, end)) //slice方法用于切出文件的一部分 |
| | | form.append('RootPath', 'Content/images/upload/') |
| | | form.append('name', file.name) |
| | | form.append('total', shardCount) |
| | | form.append('index', i + 1) |
| | | |
| | | if (i < shardCount) { |
| | | i++ |
| | | Api.getFileUpload(file).then(res => { |
| | | console.log(res) |
| | | Api.getFileUpload(form).then(res => { |
| | | if (res) { |
| | | this.setState({ |
| | | percent: Math.floor(100 * (i / shardCount)) |
| | | }) |
| | | this.shardupload(file, shardSize, shardCount, i) |
| | | this.shardupload(file, shardSize, shardCount, i, fileList) |
| | | } |
| | | }) |
| | | } else { |
| | |
| | | } |
| | | |
| | | beforeUpload = (file, fileList) => { |
| | | let shardSize = 200 * 1024 * 1024 |
| | | console.log(file) |
| | | let shardSize = 2 * 1024 * 1024 |
| | | // let shardSize = 3 * 1024 |
| | | |
| | | if (file.size > shardSize) { |
| | | this.setState({ |
| | |
| | | percent: 0 |
| | | }) |
| | | let shardCount = Math.ceil(file.size / shardSize) |
| | | this.shardupload(file, shardSize, shardCount, 0) |
| | | this.shardupload(file, shardSize, shardCount, 0, fileList) |
| | | return false |
| | | } else { |
| | | return true |
| | |
| | | fileList: value, |
| | | action: baseUrl, |
| | | method: 'post', |
| | | multiple: true, |
| | | // headers: {'RootPath': 'Content/images/upload/'}, |
| | | onChange: this.onChange, |
| | | onRemove: this.onRemove, |
| | | data: this.getExtraData, |
| | |
| | | return ( |
| | | <Upload {...props}> |
| | | <Button> |
| | | <Icon type="upload" /> Click to Upload |
| | | <Icon type="upload" /> 点击上传 |
| | | </Button> |
| | | {showprogress ? <Progress percent={percent} size="small" /> : null} |
| | | </Upload> |