| | |
| | | } |
| | | } |
| | | |
| | | 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 => { |
| | | 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 |