优化上传文件路径
This commit is contained in:
parent
2e3a373da4
commit
9421179880
|
|
@ -57,7 +57,7 @@ public class UploadFileController extends BaseController {
|
||||||
if (null != module) {
|
if (null != module) {
|
||||||
filePath=module+ File.separator+ DateUtil.today()+ File.separator;
|
filePath=module+ File.separator+ DateUtil.today()+ File.separator;
|
||||||
}
|
}
|
||||||
String fileName = FileUploadUtils.upload( Global.getAvatarPath()+filePath, file,originalFileName);
|
String fileName = FileUploadUtils.upload( Global.getAvatarPath()+filePath, file,false,originalFileName);
|
||||||
AjaxResult ajaxResult = new AjaxResult();
|
AjaxResult ajaxResult = new AjaxResult();
|
||||||
ajaxResult.put( "fileName", filePath+fileName );
|
ajaxResult.put( "fileName", filePath+fileName );
|
||||||
ajaxResult.put( "code", "200" );
|
ajaxResult.put( "code", "200" );
|
||||||
|
|
|
||||||
|
|
@ -54,7 +54,7 @@ public class FileUploadUtils {
|
||||||
*/
|
*/
|
||||||
public static final String upload(MultipartFile file) throws IOException {
|
public static final String upload(MultipartFile file) throws IOException {
|
||||||
try {
|
try {
|
||||||
return upload( getDefaultBaseDir(), file, FileUploadUtils.IMAGE_JPG_EXTENSION );
|
return upload( getDefaultBaseDir(), file,true, FileUploadUtils.IMAGE_JPG_EXTENSION );
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new IOException( e );
|
throw new IOException( e );
|
||||||
}
|
}
|
||||||
|
|
@ -70,7 +70,7 @@ public class FileUploadUtils {
|
||||||
*/
|
*/
|
||||||
public static final String upload(String baseDir, MultipartFile file) throws IOException {
|
public static final String upload(String baseDir, MultipartFile file) throws IOException {
|
||||||
try {
|
try {
|
||||||
return upload( baseDir, file, FileUploadUtils.IMAGE_JPG_EXTENSION );
|
return upload( baseDir, file,true, FileUploadUtils.IMAGE_JPG_EXTENSION );
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new IOException( e );
|
throw new IOException( e );
|
||||||
}
|
}
|
||||||
|
|
@ -88,7 +88,7 @@ public class FileUploadUtils {
|
||||||
* @throws FileNameLengthLimitExceededException 文件名太长
|
* @throws FileNameLengthLimitExceededException 文件名太长
|
||||||
* @throws IOException 比如读写文件出错时
|
* @throws IOException 比如读写文件出错时
|
||||||
*/
|
*/
|
||||||
public static final String upload(String baseDir, MultipartFile file, String extension)
|
public static final String upload(String baseDir, MultipartFile file,boolean needDatePathAndRandomName, String extension)
|
||||||
throws FileSizeLimitExceededException, IOException, FileNameLengthLimitExceededException {
|
throws FileSizeLimitExceededException, IOException, FileNameLengthLimitExceededException {
|
||||||
|
|
||||||
int fileNamelength = file.getOriginalFilename().length();
|
int fileNamelength = file.getOriginalFilename().length();
|
||||||
|
|
@ -99,7 +99,10 @@ public class FileUploadUtils {
|
||||||
|
|
||||||
assertAllowed( file );
|
assertAllowed( file );
|
||||||
|
|
||||||
String fileName = encodingFilename( file.getOriginalFilename(), extension );
|
String fileName = extension;
|
||||||
|
if(needDatePathAndRandomName){
|
||||||
|
fileName =encodingFilename( file.getOriginalFilename(), extension );
|
||||||
|
}
|
||||||
|
|
||||||
File desc = getAbsoluteFile( baseDir, baseDir + fileName );
|
File desc = getAbsoluteFile( baseDir, baseDir + fileName );
|
||||||
file.transferTo( desc );
|
file.transferTo( desc );
|
||||||
|
|
@ -127,7 +130,7 @@ public class FileUploadUtils {
|
||||||
return filename;
|
return filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**` 、。,
|
||||||
* 文件大小校验
|
* 文件大小校验
|
||||||
*
|
*
|
||||||
* @param file 上传的文件
|
* @param file 上传的文件
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue