728x90
파이썬 간단한 파일 공유
공유할 폴더로 이동후에
python3 -m http.server 8000
서버아이피:8000으로 접속하면 파일목록이 보인다.
728x90
파이썬 간단한 파일 공유
공유할 폴더로 이동후에
python3 -m http.server 8000
서버아이피:8000으로 접속하면 파일목록이 보인다.
Spring 서버 to 서버 파일 전송
A 서버에서 B서버로 파일 전송
[보내는 서버]
@RequestMapping(value = "/upload", method = RequestMethod.POST)
public ResponseEntity<?> uploadImages(@RequestPart("images") final MultipartFile[] files) throws IOException {
LinkedMultiValueMap<String, Object> map = new LinkedMultiValueMap<>();
String response;
HttpStatus httpStatus = HttpStatus.CREATED;
try {
for (MultipartFile file : files) {
if (!file.isEmpty()) {
map.add("images", new MultipartInputStreamFileResource(file.getInputStream(), file.getOriginalFilename()));
}
}
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.MULTIPART_FORM_DATA);
String url = "http://example.com/upload";
HttpEntity<LinkedMultiValueMap<String, Object>> requestEntity = new HttpEntity<>(map, headers);
response = restTemplate.postForObject(url, requestEntity, String.class);
} catch (HttpStatusCodeException e) {
httpStatus = HttpStatus.valueOf(e.getStatusCode().value());
response = e.getResponseBodyAsString();
} catch (Exception e) {
httpStatus = HttpStatus.INTERNAL_SERVER_ERROR;
response = e.getMessage();
}
return new ResponseEntity<>(response, httpStatus);
}
class MultipartInputStreamFileResource extends InputStreamResource {
private final String filename;
MultipartInputStreamFileResource(InputStream inputStream, String filename) {
super(inputStream);
this.filename = filename;
}
@Override
public String getFilename() {
return this.filename;
}
@Override
public long contentLength() throws IOException {
return -1; // we do not want to generally read the whole stream into memory ...
}
}
[받는 서버]
@RequestMapping("/upload")
@ResponseBody
public String upload(List<MultipartFile> files) {
files.forEach(file -> {
System.out.println(file.getContentType());
System.out.println(file.getOriginalFilename());
});
HashMap<String, String> resultMap = new HashMap<>();
resultMap.put("result", "success");
return ResponseEntity.ok(resultMap);
}
[참고]
https://velog.io/@dailylifecoding/Spring-MVC-multipartFile-sending-technique
[Spring MVC] MultipartFile을 서버 또는 Java 코드에서 전송하는 방법
Java 혹은 Spring MVC + Servlet 기반의 서버에서 MultipartForm 을 전송하는 방식에 대해서 알아본다.
velog.io
How to send Multipart form data with restTemplate Spring-mvc
I am trying to upload a file with RestTemplate to Raspberry Pi with Jetty. On Pi there is a servlet running: protected void doPost(HttpServletReq...
stackoverflow.com
spring mybatis 특정 sql log 숨기기 (0) | 2023.08.04 |
---|---|
Interceptor에서 request url에 jsp 경로로 여러번 호출될때 (0) | 2023.08.04 |
톰캣 9.0 한글 깨짐 및 logback 한글깨짐 (0) | 2023.07.26 |
spring 전자 정부 파일이미지 (0) | 2023.04.01 |
Spring RestTemplate으로 양식 데이터를 POST하는 방법 (0) | 2023.03.29 |