-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
61 lines (51 loc) · 1.12 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import React, { Component } from 'react';
import axios from 'axios';
import './App.css';
class App extends Component {
constructor() {
super();
this.state = {
images: [],
};
}
onImageChange = event => {
console.log(event.target.files);
this.setState({
images: event.target.files,
});
};
onSubmit = e => {
e.preventDefault();
const formData = new FormData();
Array.from(this.state.images).forEach(image => {
formData.append('files', image);
});
axios
.post(`http://localhost/api/<apiname>/upload`, formData, {
headers: { 'Content-Type': 'multipart/form-data' },
})
.then(res => {
console.log(res);
})
.catch(err => {
console.log(err);
});
};
render() {
return (
<div className="App">
<form onSubmit={this.onSubmit}>
<input
type="file"
name="files"
onChange={this.onImageChange}
alt="image"
/>
<br />
<button type="submit">Send</button>
</form>
</div>
);
}
}
export default App;