保存进度!

This commit is contained in:
Kane 2023-01-24 00:35:31 +08:00
parent 1f988323d4
commit c568da745f
2 changed files with 23 additions and 5 deletions

View File

@ -2,7 +2,7 @@
* @Author: Kane * @Author: Kane
* @Date: 2023-01-22 23:11:26 * @Date: 2023-01-22 23:11:26
* @LastEditors: Kane * @LastEditors: Kane
* @LastEditTime: 2023-01-23 23:22:10 * @LastEditTime: 2023-01-24 00:35:02
* @FilePath: \AdminSys\src\main\java\com\cpic\xim\web\controllers\FileUpload\FileUpload.java * @FilePath: \AdminSys\src\main\java\com\cpic\xim\web\controllers\FileUpload\FileUpload.java
* @Description: 用于接受上传文件的Controller * @Description: 用于接受上传文件的Controller
* *
@ -24,6 +24,13 @@ import org.springframework.web.multipart.MultipartFile;
@RequestMapping( path = "/file" ) @RequestMapping( path = "/file" )
public class FileUpload public class FileUpload
{ {
/*****************************************************
* 接收上传文件并保存到临时目录
* 1临时目录下再用sessionID作为子目录保存文件
* 2保存时不更改文件名会覆盖同名文件
* 3MultipartFile参数形参名称必须和请求form中file标签的name属性一致否则值为null
* 4返回值为接收结果和文件保存路径
*****************************************************/
@RequestMapping( path = "/file-upload.do" ) @RequestMapping( path = "/file-upload.do" )
@ResponseBody @ResponseBody
public FileUploadResult getUploadFile( @RequestParam( "task-name" ) String taskName, public FileUploadResult getUploadFile( @RequestParam( "task-name" ) String taskName,
@ -35,10 +42,13 @@ public class FileUpload
Vector<String> fileNames = new Vector<String>(); Vector<String> fileNames = new Vector<String>();
int fileCount = files.length; int fileCount = files.length;
// 防御验证
if ( files.length == 0 ) if ( files.length == 0 )
{ {
result.setSuccess( false ); result.setSuccess( false );
result.setMessage( "此接口用于上传文件!" ); result.setMessage( "此接口用于上传文件!" );
return result;
} }
result.setSuccess( true ); result.setSuccess( true );
@ -46,9 +56,17 @@ public class FileUpload
for ( MultipartFile file : files ) for ( MultipartFile file : files )
{ {
String fileName = file.getName(); if ( file.isEmpty() )
{
// 文件长度位0跳过
continue;
}
fileNames.add( fileName ); String filePath =
request.getServletContext().getRealPath( "/temp/upload/" + sessionID );
String fileName = file.getOriginalFilename();
fileNames.add( file.getOriginalFilename() );
} }
result.setFileList( fileNames ); result.setFileList( fileNames );

View File

@ -2,7 +2,7 @@
* @Author: Kane * @Author: Kane
* @Date: 2023-01-12 15:01:22 * @Date: 2023-01-12 15:01:22
* @LastEditors: Kane * @LastEditors: Kane
* @LastEditTime: 2023-01-24 00:07:36 * @LastEditTime: 2023-01-24 00:21:51
* @FilePath: \AdminSys\src\main\java\com\cpic\xim\web\filters\token\TokenFilter.java * @FilePath: \AdminSys\src\main\java\com\cpic\xim\web\filters\token\TokenFilter.java
* @Description: 用于检查token的过滤器 * @Description: 用于检查token的过滤器
* *
@ -23,7 +23,7 @@ import javax.servlet.http.HttpServletResponse;
public class TokenFilter implements Filter public class TokenFilter implements Filter
{ {
/***************************************************** /*****************************************************
* * 对请求的token进行验证
*****************************************************/ *****************************************************/
@Override @Override
public void doFilter( ServletRequest req, ServletResponse resp, FilterChain chain ) public void doFilter( ServletRequest req, ServletResponse resp, FilterChain chain )