1、搭建一个eureka-server注册中心工程

该工程比较简洁,没有太多配置,不在描述,单节点,服务端口:8888

2、创建zuul-gateway网关工程

2.1、工程pom依赖

<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-zuul</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>

</dependencies>

2.2、工程配置文件:zuul-gateway\src\main\resources\bootstrap.yml

spring:
application:
name: zuul-gateway
servlet: #spring boot2.0之前是http
multipart:
enabled: true # 使用http multipart上传处理
max-file-size: 100MB # 设置单个文件的最大长度,默认1M,如不限制配置为-1
max-request-size: 100MB # 设置最大的请求文件的大小,默认10M,如不限制配置为-1
file-size-threshold: 10MB # 当上传文件达到10MB的时候进行磁盘写入
location: / # 上传的临时目录
server:
port: 5555
eureka:
client:
serviceUrl:
defaultZone: http://${eureka.host:127.0.0.1}:${eureka.port:8888}/eureka/
instance:
prefer-ip-address: true ##### Hystrix默认超时时间为1秒,如果要上传大文件,为避免超时,稍微设大一点
hystrix:
command:
default:
execution:
isolation:
thread:
timeoutInMilliseconds: 30000
ribbon:
ConnectTimeout: 3000
ReadTimeout: 30000

注意:

SpringBoot版本之间有很大的变化,1.4.x 版本前:

multipart:
enabled: true
max-file-size: 100MB

1.5.x - 2.x 之间:

spring:
http:
multipart:
enabled: true
max-file-size: 100MB

2.x 之后:

spring:
servlet:
multipart:
enabled: true
max-file-size: 100MB

2.3、网关工程启动类:

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.zuul.EnableZuulProxy; @SpringBootApplication
@EnableDiscoveryClient
@EnableZuulProxy
public class ZuulServerApplication { public static void main(String[] args) {
SpringApplication.run(ZuulServerApplication.class, args);
}
}

2.4、上传代码:

import java.io.File;
import java.io.IOException; import org.springframework.stereotype.Controller;
import org.springframework.util.FileCopyUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile; @Controller
public class ZuulUploadController { @PostMapping("/upload")
@ResponseBody
public String uploadFile(@RequestParam(value = "file", required = true) MultipartFile file) throws IOException {
byte[] bytes = file.getBytes();
File fileToSave = new File(file.getOriginalFilename());
FileCopyUtils.copy(bytes, fileToSave);
return fileToSave.getAbsolutePath();
}
}

3、测试,上传成功返回文件绝对路径:

 

Zuul【文件上传】的更多相关文章

  1. Spring Cloud Zuul 中文文件上传乱码

    原文地址:https://segmentfault.com/a/1190000011650034 1 描述 使用Spring Cloud Zuul进行路由转发时候吗,文件上传会造成中文乱码“?”.1. ...

  2. leyou_05_文件上传

    1.搭建一个新的微服务Ly-upload用来上传文件 2.导入文件上传到额依赖 <dependencies> <dependency> <groupId>org.s ...

  3. jquery.uploadify文件上传组件

    1.jquery.uploadify简介 在ASP.NET中上传的控件有很多,比如.NET自带的FileUpload,以及SWFUpload,Uploadify等等,尤其后面两个控件的用户体验比较好, ...

  4. 11、Struts2 的文件上传和下载

    文件上传 表单准备 要想使用 HTML 表单上传一个或多个文件 须把 HTML 表单的 enctype 属性设置为 multipart/form-data 须把 HTML 表单的method 属性设置 ...

  5. Java FtpClient 实现文件上传服务

    一.Ubuntu 安装 Vsftpd 服务 1.安装 sudo apt-get install vsftpd 2.添加用户(uftp) sudo useradd -d /home/uftp -s /b ...

  6. 小兔Java教程 - 三分钟学会Java文件上传

    今天群里正好有人问起了Java文件上传的事情,本来这是Java里面的知识点,而我目前最主要的精力还是放在了JS的部分.不过反正也不麻烦,我就专门开一贴来聊聊Java文件上传的基本实现方法吧. 话不多说 ...

  7. ,net core mvc 文件上传

    工作用到文件上传的功能,在这个分享下 ~~ Controller: public class PictureController : Controller { private IHostingEnvi ...

  8. Web开发安全之文件上传安全

    很长一段时间像我这种菜鸡搞一个网站第一时间反应就是找上传,找上传.借此机会把文件上传的安全问题总结一下. 首先看一下DVWA给出的Impossible级别的完整代码: <?php if( iss ...

  9. AutoIt实现Webdriver自动化测试文件上传

    在运用WebDriver进行自动化测试时,由于WebDriver自身的限制,对于上传文件时Windows弹出的文件选择窗口无法控制,通过在网上查找资料锁定使用AutoIt来控制文件上传窗口. Auto ...

  10. Struts的文件上传下载

    Struts的文件上传下载 1.文件上传 Struts2的文件上传也是使用fileUpload的组件,这个组默认是集合在框架里面的.且是使用拦截器:<interceptor name=" ...

随机推荐

  1. python3 之metaclass

    如果希望创建某一批类全部具有某种特征,则可通过 metaclass 来实现.使用 metaclass 可以在创建类时动态修改类定义. 为了使用 metaclass 动态修改类定义,程序需要先定义 me ...

  2. 【洛谷】P3188 [HNOI2007]梦幻岛宝珠

    题目描述 给你N颗宝石,每颗宝石都有重量和价值.要你从这些宝石中选取一些宝石,保证总重量不超过W,且总价值最大为,并输出最大的总价值.  数据范围:N<=100;W<=2^30,并且保证每 ...

  3. css自定义属性和简单效果

    简介 CSS Variables,一个并不是那么新的东西,但对css来说绝对是一场革命. 之前使用变量的时候,需要借助sass.less等预处理工具来实现,现在我们可以直接使用css来声明变量. 兼容 ...

  4. Prometheus初体验(三)

    一.安装部署 Prometheus基于Golang编写,编译后的软件包,不依赖于任何的第三方依赖.用户只需要下载对应平台的二进制包,解压并且添加基本的配置即可正常启动Prometheus Server ...

  5. springboot项目获取resource下的文件

    package com.expr.exceldemo; import org.springframework.core.io.ClassPathResource; public class Test ...

  6. 容易被忽视的python装饰器的特性

    今天发现了装饰器的另一种用法,下面就先上代码: data_list = [] def data_item(func): data_list.append(func) return func @data ...

  7. Mybatis异常-java.lang.IllegalArgumentException: invalid comparison:java.util.Date and java.lang.String

    原因:在Mapper.xml中对非字符串类型的数据进行了是否为空判断,如date类型的数据Create_Date != '',decimal类型的数据price != ''都会报这个错误 只有字符串才 ...

  8. 像母语者一样说美语 How to Improve Spoken American English - Sound like a Native Speaker

    视频讲解: 视频详情见:https://www.bilibili.com/video/av75075387/ 总结分析: 001 要点总结: 1. 本富兰克林方法: 要你写下一切听到的东西 2. 辅音 ...

  9. python try except 出现异常时,except 中如何返回异常的信息字符串

    https://docs.python.org/3/tutorial/errors.html#handling-exceptions https://docs.python.org/3/library ...

  10. PHP7 MongoDB 使用方法

    原文链接: http://www.zhaokeli.com/article/8574.html MongoDb原生操作 Mongodb连接 PHP7 连接 MongoDB 语法如下: 复制代码 $ma ...