파일을 직접 보내지 않고 FormBodyPart에서 컨트롤러를 사용하여 파일을 보내려고합니다. 다음은 파일 모음을 만들기위한 코드입니다.Spring org.springframework.web.multipart.support.MissingServletRequestPartException, Required 요청 부분 'file'이 없습니다.
private void addFile(Collection<FormBodyPart> parts, File inputFile, String fileType)
throws ClassificationException {
if (inputFile == null) {
throw new ClassificationException("Null input file provided");
}
if (!inputFile.exists()) {
throw new ClassificationException("Input file not found: " + inputFile.getAbsolutePath());
}
if (fileType != null) {
String charset = "UTF-8";
parts.add(new FormBodyPart("file", new FileBody(inputFile, fileType, charset)));
} else {
parts.add(new FormBodyPart("file", new FileBody(inputFile, inputFile.getName())));
}
}
파트 콜렉션은 파일을 포함하는 arraylist입니다. 여기
에서 HTTP 엔터티를 설정하기위한 내 코드입니다HttpPost httppost = new HttpPost("http://localhost:9000/upload1");
MultipartEntity reqEntity1 = new MultipartEntity();
FormBodyPart part1;
for (Iterator i$ = parts.iterator(); i$.hasNext(); reqEntity1.addPart(part1)) {
part1 = (FormBodyPart) i$.next();
System.out.println(part1.getHeader());
}
httppost.setEntity(reqEntity1);
HttpResponse response = httpclient.execute(httppost);
System.out.println(response);
컨트롤러의 내 메소드 선언은
String index(@RequestParam("file") MultipartFile uploadfile)
내가 진술 서버에서 오류를 얻고있다
[ 400] { "타임 스탬프": 1474898550131, "상태": 400, "오류": "잘못된 요청", "예외": "o rg.springframework.web.multipart.support.MissingServletRequestPartException ","메시지 ":"필수 요청 부분 '파일'경로 ","존재하지 않는 ":"/ upload1 "}
내 dispatcher.xml 이미 포함 multipartResolver의 bean.
저는 웹 서비스에 익숙하지 않고 어리석은 실수를 저지르고있을 수도 있습니다. 제발 도와주세요. 미리 감사드립니다.
변수 이름에'$'을 사용하지 마십시오. [Java 언어 사양 §3.8] (https://docs.oracle.com/javase/specs/jls/se8/html/jls-3.html#jls-3.8) : *'$'기호는 기계적으로 생성 된 소스 코드이거나 드물게 레거시 시스템의 기존 이름에 액세스 할 수 없습니다. * – Andreas
'part'는 비어 있지 않습니까? – Andreas
"[[email protected]]"부분을 인쇄 할 때 비어 있다고 생각하지 않습니다. –