king
2020-02-21 063b983daaf51a7f1e8677bde1e9c0e618866c91
src/tabviews/tableshare/fileupload/index.jsx
@@ -51,33 +51,31 @@
    }
  }
  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 {
@@ -95,8 +93,8 @@
  }
  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({
@@ -104,7 +102,7 @@
        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
@@ -121,6 +119,8 @@
      fileList: value,
      action: baseUrl,
      method: 'post',
      multiple: true,
      // headers: {'RootPath': 'Content/images/upload/'},
      onChange: this.onChange,
      onRemove: this.onRemove,
      data: this.getExtraData,
@@ -129,7 +129,7 @@
    return (
      <Upload {...props}>
        <Button>
          <Icon type="upload" /> Click to Upload
          <Icon type="upload" /> 点击上传
        </Button>
        {showprogress ? <Progress percent={percent} size="small" /> : null}
      </Upload>