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. hdoj 1010-Tempter of the Bone

    Problem Description The doggie found a bone in an ancient maze, which fascinated him a lot. However, ...

  2. 深入理解JVM虚拟机12:JVM性能管理神器VisualVM介绍与实战

    一.VisualVM是什么? VisualVM是一款免费的JAVA虚拟机图形化监控分析工具. 1.  拥有图形化的监控界面.    2. 提供本地.远程的JVM监控分析功能.    3. 是一款免费的 ...

  3. IntelliJ IDEA配置Tomcat运行web项目

    小白一枚,借鉴了好多人的博客,然后自己总结了一些图,尽量的详细.在配置的过程中,有许多疑问.如果读者看到后能给我解答的,请留言.Idea请各位自己安装好,还需要安装Maven和Tomcat,各自配置好 ...

  4. 利用Git上传项目到github以及遇到的问题

    今天学习如何利用git从本地端上传项目,以及遇到问题的解决方法 1.要有自己的github账号,并创建一个仓库, 2.输入仓库的名称,直接Create 注:记住常见成功后的这个地址,后边要用到: 3. ...

  5. SSM项目启动报错WEB-INF\lib\javax.servlet-api-4.0.1.jar) - jar not loaded. See Servlet Spec 3.0, section 10

    错误信息: validateJarFile(D:\tomcat_ryxunit\webapps\ryx_unit\WEB-INF\lib\javax.servlet.jar) - jar not lo ...

  6. nginx配置静态资源与动态访问分离【转】

    在前面的博客中<说说 NGINX 的配置及优化>的 2.5 小节里面,提到 location 模块是 nginx 中用的最多的,也是最重要的模块,负载均衡.反向代理.虚拟域名等都与它相关. ...

  7. ping 域名

  8. 卸载node和npm

    sudo npm uninstall npm -g yum remove nodejs npm -y

  9. 安装ORACLE服务出现Oracle Net Configuration Assistant 失败问题【我】

    安装ORACLE服务出现Oracle Net Configuration Assistant 失败问题 本地安装oracle11g,报错提示: 参考下面文章: 报错原因: 主要是对文件系统的访问权限问 ...

  10. QQ第三方登录回调地址的问题

    如题,维护以前的项目,发现原来QQ的第三方登录竟然失败了.回调地址的问题 原来是以前的规则变了.好吧,那就改,谁叫我不是改变规则的人. 中途浪费了点时间,项目很大,我一下也找不到项目里那个接口调用的, ...