本文整理汇总了Java中org.apache.commons.fileupload.servlet.ServletFileUpload.isMultipartContent方法的典型用法代码示例。如果您正苦于以下问题:Java ServletFileUpload.isMultipartContent方法的具体用法?Java ServletFileUpload.isMultipartContent怎么用?Java ServletFileUpload.isMultipartContent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.fileupload.servlet.ServletFileUpload
的用法示例。
在下文中一共展示了ServletFileUpload.isMultipartContent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: fileUpload
import org.apache.commons.fileupload.servlet.ServletFileUpload; //导入方法依赖的package包/类
/**
* 上传文件
*
* @param param
* @param request
* @return
* @throws Exception
*/
@RequestMapping(value = "/fileUpload", method = RequestMethod.POST)
@ResponseBody
public ResponseEntity fileUpload(MultipartFileParam param, HttpServletRequest request) {
boolean isMultipart = ServletFileUpload.isMultipartContent(request);
if (isMultipart) {
logger.info("上传文件start。");
try {
// 方法1
//storageService.uploadFileRandomAccessFile(param);
// 方法2 这个更快点
storageService.uploadFileByMappedByteBuffer(param);
} catch (IOException e) {
e.printStackTrace();
logger.error("文件上传失败。{}", param.toString());
}
logger.info("上传文件end。");
}
return ResponseEntity.ok().body("上传成功。");
}
示例2: getServiceResult
import org.apache.commons.fileupload.servlet.ServletFileUpload; //导入方法依赖的package包/类
protected void getServiceResult(HttpServletRequest request, Document document) throws Exception {
// Check that we have a file upload request
boolean isMultipart = ServletFileUpload.isMultipartContent(request);
if (!isMultipart)
throw new IllegalArgumentException("Not multipart content!");
FileItemFactory factory = new DiskFileItemFactory();
// Create a new file upload handler
ServletFileUpload upload = new ServletFileUpload(factory);
// Parse the request
List<FileItem> items = GenericUtils.cast(upload.parseRequest(request));
// Process the uploaded items
handleFormFields(request);
for (FileItem item : items) {
doUpload(request, document, item);
}
}
示例3: isValidImage
import org.apache.commons.fileupload.servlet.ServletFileUpload; //导入方法依赖的package包/类
public static String isValidImage(HttpServletRequest request, MultipartFile file){
//最大文件大小
long maxSize = 5242880;
//定义允许上传的文件扩展名
HashMap<String, String> extMap = new HashMap<String, String>();
extMap.put("image", "gif,jpg,jpeg,png,bmp");
if(!ServletFileUpload.isMultipartContent(request)){
return "请选择文件";
}
if(file.getSize() > maxSize){
return "上传文件大小超过5MB限制";
}
//检查扩展名
String fileName=file.getOriginalFilename();
String fileExt = fileName.substring(fileName.lastIndexOf(".") + 1).toLowerCase();
if(!Arrays.<String>asList(extMap.get("image").split(",")).contains(fileExt)){
return "上传文件扩展名是不允许的扩展名\n只允许" + extMap.get("image") + "格式";
}
return "valid";
}
示例4: VariablesBase
import org.apache.commons.fileupload.servlet.ServletFileUpload; //导入方法依赖的package包/类
/**
* Basic constructor that takes the request object and saves it to be used by the subsequent
* methods
*
* @param request
* HttpServletRequest object originating from the user request.
*/
@SuppressWarnings("unchecked")
public VariablesBase(HttpServletRequest request) {
if (request == null) {
// logging exception to obtain stack trace to pinpoint the cause
log4j.warn("Creating a VariablesBase with a null request", new Exception());
this.session = new HttpSessionWrapper();
this.isMultipart = false;
} else {
this.session = request.getSession(true);
this.httpRequest = request;
this.isMultipart = ServletFileUpload.isMultipartContent(new ServletRequestContext(request));
if (isMultipart) {
DiskFileItemFactory factory = new DiskFileItemFactory();
// factory.setSizeThreshold(yourMaxMemorySize);
// factory.setRepositoryPath(yourTempDirectory);
ServletFileUpload upload = new ServletFileUpload(factory);
// upload.setSizeMax(yourMaxRequestSize);
try {
items = upload.parseRequest(request);
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
}
示例5: SimpleRequestObject
import org.apache.commons.fileupload.servlet.ServletFileUpload; //导入方法依赖的package包/类
public SimpleRequestObject(final HttpMethod method,
final HttpServletRequest req,
final File tempFolder,
final long maxDiskFile,
final int maxMemFile,
final boolean allowDiskCache) {
this.method = method;
this.req = req;
if(ServletFileUpload.isMultipartContent(req)) {
this.variableRequestHandler = new VRFile();
} else {
this.variableRequestHandler = new VRNormal();
}
this.variableRequestHandler.setFileTempDirectory(tempFolder);
this.variableRequestHandler.setMaxFileUploadSize(maxDiskFile);
this.variableRequestHandler.setMaxMemFileSize(maxMemFile);
this.variableRequestHandler.allowFilesOnDisk(allowDiskCache);
final javax.servlet.http.Cookie[] cs = this.req.getCookies();
if(cs != null) {
for(final javax.servlet.http.Cookie c: cs) {
cookies.put(c.getName(), new HttpCookie(c));
}
}
}
示例6: copy
import org.apache.commons.fileupload.servlet.ServletFileUpload; //导入方法依赖的package包/类
/**
* Copy all request params from the model.
*
* @param m
* the model of source
*/
final public void copy(Model m) {
this.req = m.req;
this.resp = m.resp;
this.contentType = m.contentType;
this.context = m.context;
this.lang = m.lang;
this.locale = m.locale;
this.login = m.login;
this.method = m.method;
this.path = m.path;
this.sid = m.sid;
this.uri = m.uri;
this._multipart = ServletFileUpload.isMultipartContent(req);
if (this._multipart) {
this.uploads = m.getFiles();
}
}
示例7: doPost
import org.apache.commons.fileupload.servlet.ServletFileUpload; //导入方法依赖的package包/类
public void doPost(HttpServletRequest req, HttpServletResponse res) {
boolean isMultipart = ServletFileUpload.isMultipartContent(req);
if (!isMultipart && req.getParameter("operation").equals("delete")){
handleDelete(req, res);
}
if (!isMultipart && req.getParameter("operation").equals("deleteAllForRecord")){
handleDeleteAllForRecord(req, res);
}
else{
try {
handleUpload(req, res);
writeOK(res);
} catch (FileUploadException ex) {
log.fatal(ex);
writeError(res, ex);
}
}
}
示例8: render
import org.apache.commons.fileupload.servlet.ServletFileUpload; //导入方法依赖的package包/类
public void render() throws IOException {
ctx.getResponse().setCharacterEncoding(charset);
String s = toString();
if (wrapMultipart && ServletFileUpload.isMultipartContent(ctx.getRequest()) && !"XMLHttpRequest".equals(ctx.getRequest().getHeader("X-Requested-With"))) {
ctx.getResponse().setContentType(contentType == null ? "text/html" : contentType);
PrintWriter pw = ctx.getResponse().getWriter();
final String s1 = "<textarea>";
final String s2 = "</textarea>";
pw.write(s1, 0, s1.length());
pw.write(s);
pw.write(s2, 0, s2.length());
return;
}
String ct = contentType;
if (ct == null) {
ct = "application/json";
String ua = ctx.getRequest().getHeader("User-Agent");
if (ua != null && ua.contains("MSIE")) {
ct = "text/plain;charset=" + charset;
}
}
ctx.getResponse().setContentType(ct);
ctx.getResponse().getWriter().write(s);
}
示例9: doPost
import org.apache.commons.fileupload.servlet.ServletFileUpload; //导入方法依赖的package包/类
/**
* Performs an HTTP POST request
*
* @param httpServletRequest The {@link HttpServletRequest} object passed
* in by the servlet engine representing the
* client request to be proxied
* @param httpServletResponse The {@link HttpServletResponse} object by which
* we can send a proxied response to the client
*/
public void doPost(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse)
throws IOException, ServletException {
// Create a standard POST request
String contentType = httpServletRequest.getContentType();
String destinationUrl = this.getProxyURL(httpServletRequest);
debug("POST Request URL: " + httpServletRequest.getRequestURL(),
" Content Type: " + contentType,
" Destination URL: " + destinationUrl);
PostMethod postMethodProxyRequest = new PostMethod(destinationUrl);
// Forward the request headers
setProxyRequestHeaders(httpServletRequest, postMethodProxyRequest);
setProxyRequestCookies(httpServletRequest, postMethodProxyRequest);
// Check if this is a mulitpart (file upload) POST
if (ServletFileUpload.isMultipartContent(httpServletRequest)) {
this.handleMultipartPost(postMethodProxyRequest, httpServletRequest);
} else {
if (contentType == null || PostMethod.FORM_URL_ENCODED_CONTENT_TYPE.equals(contentType)) {
this.handleStandardPost(postMethodProxyRequest, httpServletRequest);
} else {
this.handleContentPost(postMethodProxyRequest, httpServletRequest);
}
}
// Execute the proxy request
this.executeProxyRequest(postMethodProxyRequest, httpServletRequest, httpServletResponse);
}
示例10: parseParamsAndFillStreams
import org.apache.commons.fileupload.servlet.ServletFileUpload; //导入方法依赖的package包/类
@Override
public SolrParams parseParamsAndFillStreams(
final HttpServletRequest req, ArrayList<ContentStream> streams ) throws Exception
{
String method = req.getMethod().toUpperCase(Locale.ROOT);
if ("GET".equals(method) || "HEAD".equals(method)) {
return SolrRequestParsers.parseQueryString(req.getQueryString());
}
if ("POST".equals( method ) ) {
if (formdata.isFormData(req)) {
return formdata.parseParamsAndFillStreams(req, streams);
}
if (ServletFileUpload.isMultipartContent(req)) {
return multipart.parseParamsAndFillStreams(req, streams);
}
return raw.parseParamsAndFillStreams(req, streams);
}
throw new SolrException( SolrException.ErrorCode.BAD_REQUEST, "Unsupported method: "+method );
}
示例11: parseParamsAndFillStreams
import org.apache.commons.fileupload.servlet.ServletFileUpload; //导入方法依赖的package包/类
@Override
public SolrParams parseParamsAndFillStreams(
final HttpServletRequest req, ArrayList<ContentStream> streams ) throws Exception
{
String method = req.getMethod().toUpperCase(Locale.ROOT);
if ("GET".equals(method) || "HEAD".equals(method)
|| ("PUT".equals(method) && req.getRequestURI().contains("/schema"))) {
return parseQueryString(req.getQueryString());
}
if ("POST".equals( method ) ) {
if (formdata.isFormData(req)) {
return formdata.parseParamsAndFillStreams(req, streams);
}
if (ServletFileUpload.isMultipartContent(req)) {
return multipart.parseParamsAndFillStreams(req, streams);
}
if (req.getContentType() != null) {
return raw.parseParamsAndFillStreams(req, streams);
}
throw new SolrException(ErrorCode.UNSUPPORTED_MEDIA_TYPE, "Must specify a Content-Type header with POST requests");
}
throw new SolrException(ErrorCode.BAD_REQUEST, "Unsupported method: " + method + " for request " + req);
}
示例12: getMultipartContent
import org.apache.commons.fileupload.servlet.ServletFileUpload; //导入方法依赖的package包/类
public Map<String, FileItem> getMultipartContent() throws FileUploadException, IllegalAccessException {
if (!ServletFileUpload.isMultipartContent(request))
throw new IllegalAccessException();
FileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(factory);
Map<String, FileItem> result = new HashMap<String, FileItem>();
@SuppressWarnings("unchecked")
List<FileItem> items = upload.parseRequest(request);
for (FileItem fi : items) {
result.put(fi.getFieldName(), fi);
}
return result;
}
示例13: hanldleReq
import org.apache.commons.fileupload.servlet.ServletFileUpload; //导入方法依赖的package包/类
@Override
protected String hanldleReq(HttpServletRequest req, HttpServletResponse res)
throws Exception {
boolean isMultipart = ServletFileUpload.isMultipartContent(req);
if (isMultipart) {
req = new HttpServletReqEx(req);
}
String action = req.getParameter("action");
if (!StringUtils.isNotEmpty(action)) {
return "pages/join";
}
if (StringUtils.equals(action, "reg")) {
return register(req, res);
}
if (StringUtils.equals(action, "checkexist")) {
checkIdExist(req, res);
return null;
}
return null;
}
示例14: parseParamsAndFillStreams
import org.apache.commons.fileupload.servlet.ServletFileUpload; //导入方法依赖的package包/类
@Override
public SolrParams parseParamsAndFillStreams(
final HttpServletRequest req, ArrayList<ContentStream> streams ) throws Exception
{
String method = req.getMethod().toUpperCase(Locale.ROOT);
if ("GET".equals(method) || "HEAD".equals(method)
|| (("PUT".equals(method) || "DELETE".equals(method))
&& (req.getRequestURI().contains("/schema")
|| req.getRequestURI().contains("/config")))) {
return parseQueryString(req.getQueryString());
}
if ("POST".equals( method ) ) {
if (formdata.isFormData(req)) {
return formdata.parseParamsAndFillStreams(req, streams);
}
if (ServletFileUpload.isMultipartContent(req)) {
return multipart.parseParamsAndFillStreams(req, streams);
}
if (req.getContentType() != null) {
return raw.parseParamsAndFillStreams(req, streams);
}
throw new SolrException(ErrorCode.UNSUPPORTED_MEDIA_TYPE, "Must specify a Content-Type header with POST requests");
}
throw new SolrException(ErrorCode.BAD_REQUEST, "Unsupported method: " + method + " for request " + req);
}
示例15: doFilter
import org.apache.commons.fileupload.servlet.ServletFileUpload; //导入方法依赖的package包/类
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
if (!(request instanceof HttpServletRequest)) {
chain.doFilter(request, response);
return;
}
HttpServletRequest httpRequest = (HttpServletRequest) request;
if (! ServletFileUpload.isMultipartContent(httpRequest)) {
chain.doFilter(request, response);
return;
}
ServletFileUpload upload = new ServletFileUpload(factory);
UploadMultipartRequestWrapper multipartRequest = new UploadMultipartRequestWrapper(httpRequest, upload);
chain.doFilter(multipartRequest, response);
}