MCPcopy Create free account
hub / github.com/Lobos/react-ui / addFile

Method addFile

src/Upload.js:69–99  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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) {

Callers

nothing calls this directly

Calls 5

handleChangeMethod · 0.95
uploadFileMethod · 0.95
formatFunction · 0.90
getLangFunction · 0.90
nextUidFunction · 0.90

Tested by

no test coverage detected