springboot如何整合vue实现上传下载文件

小编给大家分享一下springboot如何整合vue实现上传下载文件,希望大家阅读完这篇文章之后都有所收获,下面让我们一起去探讨吧!

创新互联专注于企业全网营销推广、网站重做改版、阳江网站定制设计、自适应品牌网站建设、H5网站设计电子商务商城网站建设、集团公司官网建设、成都外贸网站建设、高端网站制作、响应式网页设计等建站业务,价格优惠性价比高,为阳江等各大城市提供网站开发制作服务。

springboot整合vue实现上传下载文件具体内容如下

环境

springboot 1.5.x

完整代码下载:springboot整合vue实现上传下载

1、上传下载文件api文件

设置上传路径,如例子:

private final static String rootPath =
System.getProperty(“user.home”)+File.separator+fileDir+File.separator;

api接口:

下载url示例:http://localhost:8080/file/download?fileName=新建文本文档.txt

//上传不要用@Controller,用@RestController
@RestController
@RequestMapping("/file")
public class FileController {
 private static final Logger logger = LoggerFactory.getLogger(FileController.class);
 //在文件操作中,不用/或者\最好,推荐使用File.separator
 private final static String fileDir="files";
 private final static String rootPath = System.getProperty("user.home")+File.separator+fileDir+File.separator;
 @RequestMapping("/upload")
 public Object uploadFile(@RequestParam("file") MultipartFile[] multipartFiles, final HttpServletResponse response, final HttpServletRequest request){
  File fileDir = new File(rootPath);
  if (!fileDir.exists() && !fileDir.isDirectory()) {
   fileDir.mkdirs();
  }
  try {
   if (multipartFiles != null && multipartFiles.length > 0) {
    for(int i = 0;i

访问:http://localhost:8080

springboot如何整合vue实现上传下载文件

上传:

springboot如何整合vue实现上传下载文件

批量上传:

springboot如何整合vue实现上传下载文件

下载:

springboot如何整合vue实现上传下载文件

2.上传大文件配置

/**
  * 设置上传大文件大小,配置文件属性设置无效
  */
 @Bean
 public MultipartConfigElement multipartConfigElement() {
  MultipartConfigFactory config = new MultipartConfigFactory();
  config.setMaxFileSize("1100MB");
  config.setMaxRequestSize("1100MB");
  return config.createMultipartConfig();
 }

3.vue前端主要部分

看完了这篇文章,相信你对“springboot如何整合vue实现上传下载文件”有了一定的了解,如果想了解更多相关知识,欢迎关注创新互联行业资讯频道,感谢各位的阅读!


本文名称:springboot如何整合vue实现上传下载文件
网页地址:http://pwwzsj.com/article/pogicg.html