从HttpServletRequest中获取文件输入流
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.multipart.MultipartResolver;
import org.springframework.web.multipart.commons.CommonsMultipartResolver;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.io.InputStream;
public class GetFileFromRequestUseSpring {
@Autowired private ServletContext servletContext;
public void getFile(HttpServletRequest request) throws IOException {
MultipartResolver mr = new CommonsMultipartResolver(servletContext);
MultipartHttpServletRequest multipartHttpServletRequest = mr.resolveMultipart(request);
MultipartFile multipartFile = multipartHttpServletRequest.getFile("file");
InputStream in = multipartFile.getInputStream();
}
}