CommonsMultipartResolver cleans up all multipart files in case of multiple files for same name as well (SPR-2784)
git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@3589 50f2f4bb-b051-0410-bef5-90022cba6387
This commit is contained in:
parent
e39f0704a2
commit
ce3326a617
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -179,7 +179,7 @@ public class CommonsPortletMultipartResolver extends CommonsFileUploadSupport
|
|||
public void cleanupMultipart(MultipartActionRequest request) {
|
||||
if (request != null) {
|
||||
try {
|
||||
cleanupFileItems(request.getFileMap().values());
|
||||
cleanupFileItems(request.getMultiFileMap());
|
||||
}
|
||||
catch (Throwable ex) {
|
||||
logger.warn("Failed to perform multipart cleanup for portlet request", ex);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -18,11 +18,10 @@ package org.springframework.web.multipart.commons;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.Collection;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
import org.apache.commons.fileupload.FileItem;
|
||||
import org.apache.commons.fileupload.FileItemFactory;
|
||||
|
|
@ -32,12 +31,12 @@ import org.apache.commons.logging.Log;
|
|||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.util.LinkedMultiValueMap;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import org.springframework.web.util.WebUtils;
|
||||
import org.springframework.http.MediaType;
|
||||
|
||||
/**
|
||||
* Base class for multipart resolvers that use Jakarta Commons FileUpload
|
||||
|
|
@ -271,14 +270,16 @@ public abstract class CommonsFileUploadSupport {
|
|||
* @param multipartFiles Collection of MultipartFile instances
|
||||
* @see org.apache.commons.fileupload.FileItem#delete()
|
||||
*/
|
||||
protected void cleanupFileItems(Collection<MultipartFile> multipartFiles) {
|
||||
for (MultipartFile file : multipartFiles) {
|
||||
if (file instanceof CommonsMultipartFile) {
|
||||
CommonsMultipartFile cmf = (CommonsMultipartFile) file;
|
||||
cmf.getFileItem().delete();
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Cleaning up multipart file [" + cmf.getName() + "] with original filename [" +
|
||||
cmf.getOriginalFilename() + "], stored " + cmf.getStorageDescription());
|
||||
protected void cleanupFileItems(MultiValueMap<String, MultipartFile> multipartFiles) {
|
||||
for (List<MultipartFile> files : multipartFiles.values()) {
|
||||
for (MultipartFile file : files) {
|
||||
if (file instanceof CommonsMultipartFile) {
|
||||
CommonsMultipartFile cmf = (CommonsMultipartFile) file;
|
||||
cmf.getFileItem().delete();
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Cleaning up multipart file [" + cmf.getName() + "] with original filename [" +
|
||||
cmf.getOriginalFilename() + "], stored " + cmf.getStorageDescription());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -20,11 +20,11 @@ import java.util.List;
|
|||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.apache.commons.fileupload.FileItem;
|
||||
import org.apache.commons.fileupload.FileItemFactory;
|
||||
import org.apache.commons.fileupload.FileUpload;
|
||||
import org.apache.commons.fileupload.FileUploadBase;
|
||||
import org.apache.commons.fileupload.FileUploadException;
|
||||
import org.apache.commons.fileupload.FileItem;
|
||||
import org.apache.commons.fileupload.servlet.ServletFileUpload;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
|
|
@ -184,7 +184,7 @@ public class CommonsMultipartResolver extends CommonsFileUploadSupport
|
|||
public void cleanupMultipart(MultipartHttpServletRequest request) {
|
||||
if (request != null) {
|
||||
try {
|
||||
cleanupFileItems(request.getFileMap().values());
|
||||
cleanupFileItems(request.getMultiFileMap());
|
||||
}
|
||||
catch (Throwable ex) {
|
||||
logger.warn("Failed to perform multipart cleanup for servlet request", ex);
|
||||
|
|
|
|||
Loading…
Reference in New Issue