@RestController
@RequestMapping(value="${hsweb.web.mappings.file:file}")
@Authorize(permission="file",
description="\u6587\u4ef6\u7ba1\u7406")
public class FileController
extends Object
FileService| 构造器和说明 |
|---|
FileController() |
| 限定符和类型 | 方法和说明 |
|---|---|
void |
downLoad(String idOrMd5,
String name,
javax.servlet.http.HttpServletResponse response,
javax.servlet.http.HttpServletRequest request)
通过文件ID下载已经上传的文件,支持断点下载
如: http://host:port/file/download/aSk2a/file.zip 将下载 ID为aSk2a的文件.并命名为file.zip
|
void |
downloadTxt(String name,
String text,
javax.servlet.http.HttpServletResponse response)
构建一个文本文件,并下载.支持GET,POST请求
|
void |
downloadZip(String name,
String dataStr,
javax.servlet.http.HttpServletResponse response)
构建并下载zip文件.仅支持POST请求
|
void |
restDownLoad(String id,
String name,
javax.servlet.http.HttpServletResponse response,
javax.servlet.http.HttpServletRequest request)
使用restful风格,通过文件ID下载已经上传的文件,支持断点下载
如: http://host:port/file/download/aSk2a/file.zip 将下载 ID为aSk2a的文件.并命名为file.zip
|
void |
setFileInfoService(FileInfoService fileInfoService) |
void |
setFileService(FileService fileService) |
ResponseMessage<FileInfoEntity> |
upload(org.springframework.web.multipart.MultipartFile file)
上传单个文件
|
ResponseMessage<List<FileInfoEntity>> |
upload(org.springframework.web.multipart.MultipartFile[] files)
上传文件,支持多文件上传.获取到文件流后,调用
FileService.saveFile(InputStream, String, String, String)进行文件保存
上传成功后,将返回资源信息如:[{"id":"fileId","name":"fileName","md5":"md5"}] |
ResponseMessage<String> |
uploadStatic(org.springframework.web.multipart.MultipartFile file) |
ResponseMessage<FileInfoEntity> |
uploadStatic(String md5) |
@Autowired public void setFileService(FileService fileService)
@Autowired public void setFileInfoService(FileInfoService fileInfoService)
@RequestMapping(value="/download-zip/{name:.+}",
method=POST)
@Authorize(action="download",
description="\u4e0b\u8f7d\u6587\u4ef6")
public void downloadZip(@PathVariable(value="name")
String name,
@RequestParam(value="data")
String dataStr,
javax.servlet.http.HttpServletResponse response)
throws IOException
name - 文件名dataStr - 数据,jsonArray. 格式:[{"name":"fileName","text":"fileText"}]response - HttpServletResponseIOException - 写出zip文件错误RuntimeException - 构建zip文件错误@RequestMapping(value="/download-text/{name:.+}",
method={GET,POST})
@Authorize(action="download",
description="\u4e0b\u8f7d\u6587\u4ef6")
public void downloadTxt(@PathVariable(value="name")
String name,
@RequestParam(value="text")
String text,
javax.servlet.http.HttpServletResponse response)
throws IOException
name - 文件名text - 文本内容response - HttpServletResponseIOException - 写出文本内容错误@RequestMapping(value="/download/{id}/{name:.+}",
method=GET)
@Authorize(action="download",
description="\u4e0b\u8f7d\u6587\u4ef6")
public void restDownLoad(@PathVariable(value="id")
String id,
@PathVariable(value="name")
String name,
javax.servlet.http.HttpServletResponse response,
javax.servlet.http.HttpServletRequest request)
throws IOException
id - 文件IDname - 文件名response - HttpServletResponserequest - HttpServletRequestIOException - 读写文件错误org.hswebframework.web.NotFoundException - 文件不存在@GetMapping(value="/download/{id}")
@Authorize(action="download",
description="\u4e0b\u8f7d\u6587\u4ef6")
public void downLoad(@PathVariable(value="id")
String idOrMd5,
@RequestParam(value="name",required=false)
String name,
javax.servlet.http.HttpServletResponse response,
javax.servlet.http.HttpServletRequest request)
throws IOException
idOrMd5 - 要下载资源文件的id或者md5值name - 自定义文件名,该文件名不能存在非法字符.如果此参数为空(null).将使用文件上传时的文件名response - HttpServletResponserequest - HttpServletRequestIOException - 读写文件错误org.hswebframework.web.NotFoundException - 文件不存在@PostMapping(value="/upload-multi")
@Authorize(action="upload",
description="\u4e0a\u4f20\u6587\u4ef6")
public ResponseMessage<List<FileInfoEntity>> upload(@RequestPart(value="files")
org.springframework.web.multipart.MultipartFile[] files)
FileService.saveFile(InputStream, String, String, String)进行文件保存
上传成功后,将返回资源信息如:[{"id":"fileId","name":"fileName","md5":"md5"}]files - 上传的文件@PostMapping(value="/upload")
@Authorize(action="upload",
description="\u4e0a\u4f20\u6587\u4ef6")
public ResponseMessage<FileInfoEntity> upload(@RequestPart(value="file")
org.springframework.web.multipart.MultipartFile file)
file - 上传文件@PostMapping(value="/upload-static")
@Authorize(action="static",
description="\u4e0a\u4f20\u9759\u6001\u6587\u4ef6")
public ResponseMessage<String> uploadStatic(@RequestPart(value="file")
org.springframework.web.multipart.MultipartFile file)
throws IOException
IOException@GetMapping(value="/md5/{md5}")
public ResponseMessage<FileInfoEntity> uploadStatic(@PathVariable
String md5)
throws IOException
IOExceptionCopyright © 2018. All rights reserved.