(file, id)
| 114 | } |
| 115 | |
| 116 | uploadFile (file, id) { |
| 117 | let { onUpload } = this.props; |
| 118 | return upload({ |
| 119 | url: this.props.action, |
| 120 | name: this.props.name, |
| 121 | cors: this.props.cors, |
| 122 | params: this.props.params, |
| 123 | withCredentials: this.props.withCredentials, |
| 124 | file: file.files[0], |
| 125 | onProgress: (e) => { |
| 126 | let progress = this.files[id]; |
| 127 | progress.style.width = (e.loaded / e.total) * 100 + '%'; |
| 128 | this.handleChange(new Error('')); |
| 129 | }, |
| 130 | onLoad: (e) => { |
| 131 | let files = this.state.files; |
| 132 | let value = e.currentTarget.responseText; |
| 133 | if (onUpload) { |
| 134 | value = onUpload(value); |
| 135 | } |
| 136 | |
| 137 | if (value instanceof Error) { |
| 138 | files[id].status = 3; |
| 139 | files[id].name = value.message; |
| 140 | } else { |
| 141 | files[id].status = 2; |
| 142 | files[id].value = value; |
| 143 | } |
| 144 | |
| 145 | this.setState({ files }); |
| 146 | this.handleChange(); |
| 147 | }, |
| 148 | onError: () => { |
| 149 | let files = this.state.files; |
| 150 | files[id].status = 3; |
| 151 | this.setState({ files }); |
| 152 | this.handleChange(); |
| 153 | } |
| 154 | }); |
| 155 | } |
| 156 | |
| 157 | start () { |
| 158 | let files = this.state.files; |
no test coverage detected