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. 和小哥哥一起刷洛谷(4) 图论之广度优先搜索BFS

    关于bfs: 你怎么会连这个都不知道!!!自己好好谷歌一下!!!(其实我也刚学) bfs伪代码: while(队列非空){ 取出队首元素u; 弹出队首元素; u染色为黑色; for(int i=0;i ...

  2. 小程序中嵌套的h5页面设置分享转发

    场景描述:当在小程序中打开h5页面时,希望小程序的转发出去的标题,图片,跳转link可以通过h5通信实现自定义. 实现方式:通过h5给小程序通信,发送标题,图片,跳转link等信息,让小程序设置分享. ...

  3. C 套接字

    套接字函数 1 创建套接字──socket() 应用程序在使用套接字前,首先必须拥有一个套接字,系统调用socket()向应用程序提供创建套接字的手段,   其调用格式如下:SOCKET PASCAL ...

  4. wrod: 突然无法输入汉字

    “文件”-“选项”-“高级”-“去掉 输入法控制处于活动状态复选框”.

  5. MongoDB数据表添加字段

    db.tshare_a.insert( { "_id" : ObjectId("57172b0f657f8bbb34d70147"), "picUrl ...

  6. win7、win10系统电脑开机后小键盘灯不亮怎么办?

    摘自:https://www.pconline.com.cn/win10/1113/11136072.html win7.win10系统 电脑开机后小键盘灯不亮怎么办?这是不少用户最近都在反馈的问题. ...

  7. 【432】COMP9024,Exercise9

    eulerianCycle.c What determines whether a graph is Eulerian or not? Write a C program that reads a g ...

  8. 深入浅出深度学习:原理剖析与python实践_黄安埠(著) pdf

    深入浅出深度学习:原理剖析与python实践 目录: 第1 部分 概要 1 1 绪论 2 1.1 人工智能.机器学习与深度学习的关系 3 1.1.1 人工智能——机器推理 4 1.1.2 机器学习—— ...

  9. LeetCode_237. Delete Node in a Linked List

    237. Delete Node in a Linked List Easy Write a function to delete a node (except the tail) in a sing ...

  10. [Log4j使用教程] JavaSE/JavaEE/SpringMVC中使用Log4j

    要想使用Log4j, 首先需要下载到Log4j的jar, Download: http://www.apache.org/dyn/closer.cgi/logging/log4j/1.2.17/log ...