-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
React 활용 - 5 : Spring에 파일데이터 전송하기 (react 다중 파일)
- Loading branch information
Showing
4 changed files
with
96 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
reactBootTemplate/src/webapp/reactspringfront/src/Screens/FileData.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import React, { useState, useEffect } from 'react'; | ||
import axios from 'axios'; | ||
|
||
function FileData() { | ||
const [file, setFile] = useState(null); //파일 | ||
|
||
const handleChangeFile = (event) => { | ||
console.log(event.target.files) | ||
setFile(event.target.files); | ||
|
||
|
||
} | ||
|
||
function Send(){ | ||
const fd = new FormData(); | ||
Object.values(file).forEach((file) => fd.append("file", file)); | ||
|
||
|
||
axios.post('/test/AxiosFileTest.do', fd, { | ||
headers: { | ||
"Content-Type": `multipart/form-data; `, | ||
}, | ||
baseURL: 'http://localhost:8080' | ||
}) | ||
.then((response) => { | ||
|
||
}) | ||
.catch((error) => { | ||
// 예외 처리 | ||
}) | ||
|
||
} | ||
return ( | ||
<div> | ||
FileData | ||
<div> | ||
fileData1: <input type="file" id="file" onChange={handleChangeFile} multiple="multiple"></input> | ||
</div> | ||
|
||
|
||
<div> | ||
<button onClick={()=> Send()}>Send</button> | ||
</div> | ||
</div> | ||
); | ||
} | ||
export default FileData; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters