Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/normangyllenhaal/file-upload
spring mvc java upload file 上传插件
https://github.com/normangyllenhaal/file-upload
java springmvc upload-file
Last synced: about 2 months ago
JSON representation
spring mvc java upload file 上传插件
- Host: GitHub
- URL: https://github.com/normangyllenhaal/file-upload
- Owner: NormanGyllenhaal
- Created: 2017-04-15T09:27:27.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-05-14T12:07:39.000Z (over 7 years ago)
- Last Synced: 2024-11-15T13:42:22.661Z (about 2 months ago)
- Topics: java, springmvc, upload-file
- Language: Java
- Homepage:
- Size: 14.6 KB
- Stars: 5
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
### java springmvc 上传插件 file upload
[![Build Status](https://travis-ci.org/NormanGyllenhaal/file-upload.svg?branch=master)](https://travis-ci.org/NormanGyllenhaal/file-upload)
- 插件功能
单个或多个文件上传
同步异步文件处理
校验文件后缀
校验文件头
保存文件到指定目录,并返回文件的url
支持图片压缩
- 在spring mvc 中使用
1. 首先加入maven依赖 ,已加入maven中央仓库 http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22top.javatool.fileuplod%22- maven 依赖
```xmltop.javatool.fileuplod
file-upload
1.0
```
2. bean 注入
```xml```
3. 代码中使用
```java
@org.springframework.beans.factory.annotation.Autowired
private FileUpload fileUpload;
@org.springframework.web.bind.annotation.RequestMapping(value = "upload")
public void testUpload(MultipartFile file,HttpServletRequest request){
//保存文件到指定路径并返回图片url
String imageUrl = fileUpload.saveFile(file,request);
//http://www.test.com/test/yyyy-MM-dd/随机数字(时间戳+6位随机数).文件后缀
}
```4. 参数说明
- filePath 文件保存到的服务器路径,如不存在自动创建(必须)
- filePrefix 文件保存到的服务器路径前缀 就是在filePath 之后加上相应的路径
- fileType 允许上传的文件后缀,如不符合返回异常
- fileHeader 允许的文件头
- host 图片保存的域名
- ip 提供 ip到host 的转换 可以在在本机配置host 文件配置 相应规则
如 0.0.0.0 www.test.com
这样在进行多个域名服务器时部署时会比较方便 如果ip存在则不启用host