Compare commits

...
Author SHA1 Message Date
mind-one005 0523f6c214 multipart 파일전송 2025-07-21 17:43:11 +09:00
mind-one005 71dd649624 developement 환경변수 자료관 주소 추가 2025-07-19 15:24:50 +09:00
mind-one005 63a0cc70af development 환경변수 추가 2025-07-19 15:22:33 +09:00
2 changed files with 101 additions and 0 deletions
+2
View File
@@ -1,9 +1,11 @@
NEXT_PUBLIC_SITE_ID = SN
NEXT_PUBLIC_PORT = 11302
NEXT_PUBLIC_PROXY_HOST = http://con.mind-one.co.kr:11302
NEXT_PUBLIC_ADDR_URL = http://con.mind-one.co.kr:11082
NEXT_PUBLIC_SERVER_API_URL = http://dev.onasys.co.kr:8000
NEXT_PUBLIC_GEOSERVER_URL = http://rsone.iptime.org:10010/geoserver
NEXT_PUBLIC_LX_GEOSERVER_URL = http://con.mind-one.co.kr:11306/geoserver #TODO 운영에서 바꿔야 함
NEXT_PUBLIC_RSONE_DC_URL = https://apigateway.rsonesoft.com #자료관 데이터
NEXT_PUBLIC_CLAIM_NAME = Authorization
NEXT_PUBLIC_AUTH_USER_ID = token-id
NEXT_PUBLIC_ACCESS_TOKEN = access-token
@@ -0,0 +1,99 @@
'use client'
// FileUpload.js
import React, { useState } from 'react';
import axios from 'axios';
const SEWERAGE_URL = process.env.NEXT_PUBLIC_SEWERAGE_API_URL || "";
function FileUpload() {
const [file, setFile] = useState(null);
const [text, setText] = useState('');
const handleFileChange = (e) => {
setFile(e.target.files[0]);
};
const handleTextChange = (e) => {
setText(e.target.value);
};
function getCookie(name:string) {
const match = document.cookie.match(new RegExp('(^| )' + name + '=([^;]+)'));
if (match && match[2]) {
return decodeURIComponent(match[2]);
}
return null;
}
const handleFindUser = (e) => {
const auth = getCookie("Authorization");
if (auth) console.log("쿠키 auth : " + auth);
fetch(SEWERAGE_URL+"/v1/inftwtAnls/users/65a00f65-8460-49af-98ec-042977e56f4b", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({authToken: auth})
}).then((data) => {
console.log(data);
});
};
const handleFindUserOna = (e) => {
const auth = getCookie("Authorization");
if (auth) console.log("쿠키 auth : " + auth);
fetch("/server/user-service/api/v1/users/65a00f65-8460-49af-98ec-042977e56f4b").then((data) => {
console.log(data);
});
};
const handleSubmit = async (e) => {
e.preventDefault();
if (!file) {
alert('파일을 선택하세요.');
return;
}
const jsonData = {
aplcnYm: '202507',
enoCd: 'ABC'
};
// JSON → Blob 으로 변환 + MIME 지정
const jsonBlob = new Blob([JSON.stringify(jsonData)], {
type: 'application/json'
});
const formData = new FormData();
formData.append('data', jsonBlob);
formData.append('inpFile', file);
try {
const response = await axios.post('http://localhost:8883/sewerage-service/api/v1/rdiiAnls/savewithfile', formData);
alert('업로드 성공: ' + response.data.message);
} catch (err) {
console.error(err);
alert('업로드 실패');
}
};
return (
<form onSubmit={handleSubmit} className="text-2xl">
<div>
<label>텍스트 입력:</label>
<input type="text" value={text} onChange={handleTextChange} />
</div>
<div>
<label>파일 선택:</label>
<input type="file" onChange={handleFileChange} />
</div>
<button type="submit" className="px-4 py-2 bg-gray-500 text-white rounded">업로드</button>
<button type="button" className="px-4 py-2 bg-gray-400 text-white rounded"
onClick={handleFindUser}>사용자조회</button>
<button type="button" className="px-4 py-2 bg-gray-200 text-white rounded"
onClick={handleFindUserOna}>사용자조회ona</button>
</form>
);
}
export default FileUpload;