0
기본적으로 서버에 파일을 업로드하는 데 사용할 수있는 클라이언트 측 파일 업로드가 있고 서버 측에서는 MultipartConfig
을 5MB로 제한 한 파일 크기가 있으며 파일이 한도를 초과하면 업로드를 중단해야합니다 방법.Java 서버에서 파일 업로드를 중단하는 방법은 무엇입니까?
서버 측 : 참고로
@MultipartConfig(location="/tmp", fileSizeThreshold=1024*1024,
maxFileSize=1024*1024*5, maxRequestSize=1024*1024*5*5)
public void doPost(HttpServletRequest request,
HttpServletResponse response) throws IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter() ;
try{
MultipartRequest multipartRequest = new MultipartRequest(request, "D:\\");
} catch(IOException e){
System.out.println(e.getMessage());
return;
}
out.print("Successfully Uploaded");
}
: 내가 가진 내 @MultipartConfig
당신은 내가 파일 제한을 초과 한 경우이에 대해 말하는 예외를 throw try and catch
이 볼 수 있듯이 내 수업
중 파일이 예외를 초과합니다. 여기서는 업로드 프로세스를 중단하고 한계를 초과 한 클라이언트에게 간단한 오류를 보내야합니다.
그래서? 응답을 사용하여 적합한 상태 코드와 원하는 것을 보내십시오. – Kayaman
'sendError'는이를 수행하기위한 바로 가기 방법입니다. – RealSkeptic
알았어. 그냥 내 조건'httpError 409'가 적당한 오류라는 것을 알았고,'catch '에'response.sendError (response.SC_CONFLICT, "File limit has exceeded");를 썼다.하지만 작동하지 않았다. – darees