()
| 67 | } |
| 68 | |
| 69 | addFile () { |
| 70 | const { accept, autoUpload, disabled, readOnly, fileSize } = this.props; |
| 71 | if (disabled || readOnly) { |
| 72 | return; |
| 73 | } |
| 74 | |
| 75 | let files = this.state.files, |
| 76 | file = document.createElement('input'); |
| 77 | file.type = 'file'; |
| 78 | file.accept = accept; |
| 79 | file.click(); |
| 80 | Events.on(file, 'change', () => { |
| 81 | let blob = file.files[0]; |
| 82 | if (blob.size / 1024 > fileSize) { |
| 83 | this.handleChange(new Error(format(getLang('validation.tips.fileSize'), fileSize))); |
| 84 | return; |
| 85 | } |
| 86 | |
| 87 | let id = nextUid(); |
| 88 | files[id] = { |
| 89 | file, |
| 90 | name: file.files[0].name, |
| 91 | status: autoUpload ? 1 : 0 |
| 92 | }; |
| 93 | |
| 94 | if (autoUpload) { |
| 95 | files[id].xhr = this.uploadFile(file, id); |
| 96 | } |
| 97 | this.setState({ files }); |
| 98 | }); |
| 99 | } |
| 100 | |
| 101 | removeFile (id) { |
| 102 | if (this.props.disabled || this.props.readOnly) { |
nothing calls this directly
no test coverage detected