- 浏览: 56029 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (93)
- java (3)
- ios (9)
- wp (15)
- android (0)
- js (1)
- 服务器 (0)
- db (0)
- linux (1)
- python (0)
- xcode (0)
- ide (2)
- maven (0)
- spring (0)
- sql (0)
- 第三方 (1)
- nexus (0)
- nginx (11)
- tomcat (0)
- jenkins (0)
- zookeeper (1)
- git (1)
- svn (0)
- uml (0)
- redis (4)
- activemq (1)
- flume (0)
- kafka (0)
- mysql (1)
- memcached (0)
- mybatis (0)
- mac (0)
- mongo (1)
- docker (6)
- cache (0)
- jvm (0)
- markdown (0)
- springboot (24)
- mycat (3)
- LTS (3)
- 运维 (0)
- opts (1)
- netty (1)
- tcc (0)
- ffmpeg (2)
- 直播 (6)
- cxf (0)
- nodejs (0)
- storm (0)
- elasticjob (0)
- php (0)
最新评论
FileUploadConfiguration.java
===================================================
@Configuration
public class FileUploadConfiguration {
@Bean
public MultipartConfigElement multipartConfigElement() {
MultipartConfigFactory factory = new MultipartConfigFactory();
// 设置文件大小限制 ,超出设置页面会抛出异常信息,
// 这样在文件上传的地方就需要进行异常信息的处理了;
factory.setMaxFileSize("256KB"); // KB,MB
/// 设置总上传数据总大小
factory.setMaxRequestSize("512KB");
// Sets the directory location where files will be stored.
// factory.setLocation("路径地址");
return factory.createMultipartConfig();
}
}
===================================================
Controller.java
===================================================
/**
* 文件上传具体实现方法(单文件上传)
*
* @param file
* @return <form method="POST" enctype="multipart/form-data" action="/upload">
* <p>
* 文件:<input type="file" name="file" />
* </p>
* <p>
* <input type="submit" value="上传" />
* </p>
* </form>
*/
@RequestMapping(value = "/upload", method = RequestMethod.POST)
@ResponseBody
public String upload(@RequestParam("file") MultipartFile file) {
if (!file.isEmpty()) {
try {
// 这里只是简单例子,文件直接输出到项目路径下。
// 实际项目中,文件需要输出到指定位置,需要在增加代码处理。
// 还有关于文件格式限制、文件大小限制,详见:中配置。
BufferedOutputStream out = new BufferedOutputStream(
new FileOutputStream(new File(file.getOriginalFilename())));
out.write(file.getBytes());
out.flush();
out.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
return "上传失败," + e.getMessage();
} catch (IOException e) {
e.printStackTrace();
return "上传失败," + e.getMessage();
}
return "上传成功";
} else {
return "上传失败,因为文件是空的.";
}
}
/**
* 多文件上传 主要是使用了MultipartHttpServletRequest和MultipartFile
*
* @param request
* @return <form method="POST" enctype="multipart/form-data"
* action="/upload/batch">
* <p>
* 文件1:<input type="file" name="file" />
* </p>
* <p>
* 文件2:<input type="file" name="file" />
* </p>
* <p>
* 文件3:<input type="file" name="file" />
* </p>
* <p>
* <input type="submit" value="上传" />
* </p>
* </form>
*/
@RequestMapping(value = "/upload/batch", method = RequestMethod.POST)
public
@ResponseBody
String batchUpload(HttpServletRequest request) {
List<MultipartFile> files = ((MultipartHttpServletRequest) request).getFiles("file");
MultipartFile file = null;
BufferedOutputStream stream = null;
for (int i = 0; i < files.size(); ++i) {
file = files.get(i);
if (!file.isEmpty()) {
try {
byte[] bytes = file.getBytes();
stream = new BufferedOutputStream(new FileOutputStream(new File(file.getOriginalFilename())));
stream.write(bytes);
stream.close();
} catch (Exception e) {
stream = null;
return "You failed to upload " + i + " => " + e.getMessage();
}
} else {
return "You failed to upload " + i + " because the file was empty.";
}
}
return "upload successful";
}
===================================================
@Configuration
public class FileUploadConfiguration {
@Bean
public MultipartConfigElement multipartConfigElement() {
MultipartConfigFactory factory = new MultipartConfigFactory();
// 设置文件大小限制 ,超出设置页面会抛出异常信息,
// 这样在文件上传的地方就需要进行异常信息的处理了;
factory.setMaxFileSize("256KB"); // KB,MB
/// 设置总上传数据总大小
factory.setMaxRequestSize("512KB");
// Sets the directory location where files will be stored.
// factory.setLocation("路径地址");
return factory.createMultipartConfig();
}
}
===================================================
Controller.java
===================================================
/**
* 文件上传具体实现方法(单文件上传)
*
* @param file
* @return <form method="POST" enctype="multipart/form-data" action="/upload">
* <p>
* 文件:<input type="file" name="file" />
* </p>
* <p>
* <input type="submit" value="上传" />
* </p>
* </form>
*/
@RequestMapping(value = "/upload", method = RequestMethod.POST)
@ResponseBody
public String upload(@RequestParam("file") MultipartFile file) {
if (!file.isEmpty()) {
try {
// 这里只是简单例子,文件直接输出到项目路径下。
// 实际项目中,文件需要输出到指定位置,需要在增加代码处理。
// 还有关于文件格式限制、文件大小限制,详见:中配置。
BufferedOutputStream out = new BufferedOutputStream(
new FileOutputStream(new File(file.getOriginalFilename())));
out.write(file.getBytes());
out.flush();
out.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
return "上传失败," + e.getMessage();
} catch (IOException e) {
e.printStackTrace();
return "上传失败," + e.getMessage();
}
return "上传成功";
} else {
return "上传失败,因为文件是空的.";
}
}
/**
* 多文件上传 主要是使用了MultipartHttpServletRequest和MultipartFile
*
* @param request
* @return <form method="POST" enctype="multipart/form-data"
* action="/upload/batch">
* <p>
* 文件1:<input type="file" name="file" />
* </p>
* <p>
* 文件2:<input type="file" name="file" />
* </p>
* <p>
* 文件3:<input type="file" name="file" />
* </p>
* <p>
* <input type="submit" value="上传" />
* </p>
* </form>
*/
@RequestMapping(value = "/upload/batch", method = RequestMethod.POST)
public
@ResponseBody
String batchUpload(HttpServletRequest request) {
List<MultipartFile> files = ((MultipartHttpServletRequest) request).getFiles("file");
MultipartFile file = null;
BufferedOutputStream stream = null;
for (int i = 0; i < files.size(); ++i) {
file = files.get(i);
if (!file.isEmpty()) {
try {
byte[] bytes = file.getBytes();
stream = new BufferedOutputStream(new FileOutputStream(new File(file.getOriginalFilename())));
stream.write(bytes);
stream.close();
} catch (Exception e) {
stream = null;
return "You failed to upload " + i + " => " + e.getMessage();
}
} else {
return "You failed to upload " + i + " because the file was empty.";
}
}
return "upload successful";
}
发表评论
-
springboot:condition
2017-07-26 11:10 322public class LinuxCondition imp ... -
springboot:tomcat启动
2017-07-20 15:02 8821.在pom.xml里设置 <packaging> ... -
springboot:shiro
2017-07-13 15:52 916第一次学习系统学习shiro 并将shiro集成到sprin ... -
springboot:servlet
2017-07-06 10:17 463Application.java ============== ... -
springboot:freemarker
2017-07-05 17:33 474pom.xml ======================= ... -
springboot:task
2017-07-05 12:11 396TaskPool.java ================= ... -
springboot:热部署
2017-07-05 11:23 313pom.xml: ====================== ... -
springboot:注解
2017-07-04 11:36 569@EnableAutoConfiguration注解 excl ... -
springboot:server属性配置
2017-07-04 10:05 672server配置 ====================== ... -
springboot:memcached
2017-07-03 17:23 863pom.xml ======================= ... -
springboot:health
2017-07-03 16:43 352<dependency> ... -
springboot:mongodb
2017-07-03 15:38 1522pom.xml ======================= ... -
springboot:quartz集群
2017-07-02 20:40 956pom.xml ======================= ... -
springboot:ControllerAdvice
2017-07-02 14:09 340全局异常拦截 //@ControllerAdvice(anno ... -
springboot:dubbo
2017-07-02 10:40 467server: ======================= ... -
springboot:amq
2017-07-01 22:20 429pom.xml ======================= ... -
springboot:redis(jedis)
2017-07-01 14:10 865application.properties ======== ... -
springboot:mybatis&druid&pagehelper
2017-07-01 13:35 365=============================== ... -
springboot:logback
2017-06-30 16:20 486=============================== ... -
springboot:interceptor
2017-06-30 14:04 592IncpConfig.java 增加拦截器config 继承W ...
相关推荐
这是一个Spring官网提供的文件上传的例子,分享在这里希望大家一块学习,该代码详细地址请参考http://spring.io/guides/gs/uploading-files/#initial。
springboot-上传-下载待办事项清单: 克隆此存储库: git clone https://github.com/hendisantika/springboot-upload-download.git 进入文件夹: cd springboot-upload-download 运行应用程序: mvn clean spring-...
smart-garden-springboot springboot后台程序 本地开发及打包之前,务必修改application.yml文件中upload-path属性,修改值为本地/服务器的图片上传绝对路径,注意路径内包含的文件夹必须已完成创建
springboot-upload-excelspringboot上传excel文件,并将文件中数据保存至mysql数据库
webupload+springboot大文件上传
该项目基于Springboot框架StandardServletMultipartResolver组件的文件上传
upload_demo.zip
错误spring boot上传文件错误The temporary upload location [/tmp/tomcat.******/work/Tomcat/localhost/ROOT] is not valid
springboot将多个文件上传到mysql 通过以下命令运行该项目: mvn clean spring-boot:run 然后打开您喜欢的浏览器,然后输入: 截屏 主页 上载页面 列出上传的页面 表结构 表格数据
springboot jar包方式运行下的图片上传与显示,其中包含完整代码demo https://www.jianshu.com/p/5e1a4e4ab994
springboot,文件上传下载demo。
Webupload + springboot 大文件上传
毕业设计基于SSM/Springboot的商城项目 图片保存路径: 可以全局搜索后替换 windows: D:/upload linux: /usr/upload mac:需要修改代码,见下面已知问题记录. 或者代码全局搜索 // todo mac需要修改地址 技术栈 ...
- 上传视频采用 **el-upload 手动上传实现**,先将**视频名称与日期存入数据表并返回id**,**携带返回的id再次调用上传视频方法** - 视频上传后需要**截取上传视频的第一帧图片为封面图存入数据表内**(思路:使用*...
demo.zip为springboot idea工程,直接启动DemoApplication fileManage.zip为vue工程,解压后运行安装npm install,启动npm run dev
毕业设计基于SpringBoot的文档管理系统、资源管理平台项目源码+数据库 介绍 bootstrap + springboot + commons-upload + mysql 资源管理平台
进入文件夹: cd SpringBoot-S3-Multi-File-Upload 在application.properties设置您的AWS凭证密钥和密钥运行应用程序: mvn clean spring-boot:run 打开您喜欢的浏览器: 主页上传图片 AWS S3映像文件夹
springboot集成minio实现了分片上传功能源码+项目说明.zip vue版本的:前端 后端 快速开始 后端 修改配置文件application.yml: minio: endpoint: accessKey: secretKey: bucketName: downloadUri: #配置...
当前默认是上传至E:\upload。 用户头像的图片读取路径为E:\upload\img\test.png 上传/下载excel的路径为E:\upload\excel 4.当前工程的访问接口有: 前往页面: localhost:8080/sbDemo/hello 获取数据: localhost:...