일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- BFS
- 프로그래머스 #파이썬 #코딩테스트 #알고리즘
- 다이나믹프로그래밍
- 프로그래머스
- 백트랙킹
- 백준 #알고리즘 #파이썬 #코딩테스트
- 자바 #java
- 투포인터
- react #리액트 #동빈나
- Dijkstra
- 알고리즘
- 다익스트라
- 프로그래머스 #파이썬 #알고리즘 #코딩테스트
- 재귀
- react #리액트 #동빈나 #나동빈 #유튜브강의
- css #웹 #생활코딩
- java #자바 #나동빈
- 코딩테스트
- PYTHON
- java #자바 #생활코딩
- css #생활코딩 #웹
- java #자바
- 파이썬 #알고리즘 #코딩테스트 #프로그래머스
- 백준
- DFS
- dp
- 백준 #파이썬 #알고리즘 #코딩테스트
- java #자바 #동빈나
- 파이썬 #백준 #알고리즘 #코딩테스트
- 파이썬
Archives
- Today
- Total
커리까지
[동빈나] 13강 - Node.js Express에서 파일 업로드 요청 처리 및 DB에 데이터 삽입 본문
728x90
SMALL
handleFormSubmit = (e) => {
e.preventDefault()
this.addCustomer()
.then((response) => {
console.log(response.data);
this.props.stateRefresh();
})
this.setState({
file: null,
userName: '',
birthday: '',
gender: '',
job: '',
fileName: '',
open: false
})
}
- CosromerAdd.js를 수정해줌
npm install --save multer
- 사용자 이미지도 업로드해야하기 때문에 새로운 패키지 설치
const multer = require('multer');
const upload = multer({dest: './upload'})
- 추가해줌
app.use('/image', express.static('./upload'));
- 업로드 폴더 공유함
- 업로드 폴더 접근 가능사용자는 image로 서버는 upload로 인식
app.post('/api/customers', upload.single('image'), (req, res) => {
let sql = 'INSERT INTO CUSTOMER VALUES (null, ?, ?, ?, ?, ?)';
let image = '/image/' + req.file.filename;
let name = req.body.name;
let birthday = req.body.birthday;
let gender = req.body.gender;
let job = req.body.job;
let params = [image, name, birthday, gender, job];
connection.query(sql, params,
(err, rows, fields) => {
res.send(rows);
}
);
});
null은 id값이기 때문에
사용자는 image로 접근하기때문에
- filename은 multer이 알아서 겹치지 않게 저장
params에 있는 값이 차례대로 들어감
728x90
LIST
'react' 카테고리의 다른 글
[동빈나] 15강 - 고객(Customer) 정보 삭제 기능 구현하기 (0) | 2021.07.04 |
---|---|
[동빈나] 14강 - 부모 컴포넌트의 상태(State) 변경을 통한 고객 정보 갱신 (0) | 2021.07.04 |
[동빈나] 12강 - 고객 추가 양식(Form) 구현 및 이벤트 핸들링 (0) | 2021.07.02 |
concurrently --kill-others-on-fail "yarn sever" "yarn client" 'concurrently'은(는) 내부 또는 외부 명령, 실행할 수 있는 프로그램, 또는 배치 파일이 아닙니다. (0) | 2021.06.27 |
11강 - 고객(Customer) DB 테이블 구축 및 Express와 연동하기 (0) | 2021.05.28 |