Zuul【文件上传】
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【文件上传】的更多相关文章
- Spring Cloud Zuul 中文文件上传乱码
原文地址:https://segmentfault.com/a/1190000011650034 1 描述 使用Spring Cloud Zuul进行路由转发时候吗,文件上传会造成中文乱码“?”.1. ...
- leyou_05_文件上传
1.搭建一个新的微服务Ly-upload用来上传文件 2.导入文件上传到额依赖 <dependencies> <dependency> <groupId>org.s ...
- jquery.uploadify文件上传组件
1.jquery.uploadify简介 在ASP.NET中上传的控件有很多,比如.NET自带的FileUpload,以及SWFUpload,Uploadify等等,尤其后面两个控件的用户体验比较好, ...
- 11、Struts2 的文件上传和下载
文件上传 表单准备 要想使用 HTML 表单上传一个或多个文件 须把 HTML 表单的 enctype 属性设置为 multipart/form-data 须把 HTML 表单的method 属性设置 ...
- Java FtpClient 实现文件上传服务
一.Ubuntu 安装 Vsftpd 服务 1.安装 sudo apt-get install vsftpd 2.添加用户(uftp) sudo useradd -d /home/uftp -s /b ...
- 小兔Java教程 - 三分钟学会Java文件上传
今天群里正好有人问起了Java文件上传的事情,本来这是Java里面的知识点,而我目前最主要的精力还是放在了JS的部分.不过反正也不麻烦,我就专门开一贴来聊聊Java文件上传的基本实现方法吧. 话不多说 ...
- ,net core mvc 文件上传
工作用到文件上传的功能,在这个分享下 ~~ Controller: public class PictureController : Controller { private IHostingEnvi ...
- Web开发安全之文件上传安全
很长一段时间像我这种菜鸡搞一个网站第一时间反应就是找上传,找上传.借此机会把文件上传的安全问题总结一下. 首先看一下DVWA给出的Impossible级别的完整代码: <?php if( iss ...
- AutoIt实现Webdriver自动化测试文件上传
在运用WebDriver进行自动化测试时,由于WebDriver自身的限制,对于上传文件时Windows弹出的文件选择窗口无法控制,通过在网上查找资料锁定使用AutoIt来控制文件上传窗口. Auto ...
- Struts的文件上传下载
Struts的文件上传下载 1.文件上传 Struts2的文件上传也是使用fileUpload的组件,这个组默认是集合在框架里面的.且是使用拦截器:<interceptor name=" ...
随机推荐
- nginx+keepalived高可用实战
1.整体架构图如下 2.环境准备 今天所配置的是keepalived+nginx 的负载均衡 下载keepalived软件 [root@LB01 tools]# wget http://www.kee ...
- Mybatis笔记(二)
目录 MyBatis 逆向工程 MyBatis Generator 使用 分页插件 1.下载分页插件 2.配置分页插件 3.使用分页插件 SSM整合(spring与springMVC) 1.创建web ...
- 雪花ID实现新增数据同步
雪花ID实现新增数据同步 GUID生成的ID,可以确保是唯一ID,但却是无序的,不适合用于数据同步. 雪花算法生成的ID(INT64)能够按照时间有序(升序)生成.只要电脑上的时间是正确的,新增的记录 ...
- 巧用 CSS 实现酷炫的充电动画
循序渐进,看看只使用 CSS ,可以鼓捣出什么样的充电动画效果. 画个电池 当然,电池充电,首先得用 CSS 画一个电池,这个不难,随便整一个: 欧了,勉强就是它了.有了电池,那接下来直接充电吧.最最 ...
- 《Linux性能及调优指南》 Linux进程管理
版权所有: 原文名称:<Linux Performance and Tuning Guidelines> 原文地址:http://www.redbooks.ibm.com/abstract ...
- Linux安装Windows字体
Linux系统使用Windows系统字体的方法 2017年12月26日 09:35:54 知行合一2018 阅读数 1989更多 分类专栏: 杂项 版权声明:本文为博主原创文章,遵循CC 4.0 ...
- Kotlin 之操作符重载
Kotlin 之操作符重载 参考: kotlin in action kotlin 官方参考文档 运算符重载 Kotlin允许我们为自己的类型提供预定义的一组操作符实现(这些操作符都对应的成员函数 ...
- Leetcode: Shortest Way to Form String
From any string, we can form a subsequence of that string by deleting some number of characters (pos ...
- flutter 路由动画
import 'package:flutter/material.dart'; import 'package:flutter_app/pages/FirstPage.dart'; void main ...
- Composer三步曲:安装、使用、发布
转载地址:https://segmentfault.com/a/1190000011858458 原文是在我自己博客中,小伙伴也可以点阅读原文进行跳转查看,还有好听的背景音乐噢~ 在现代化的PHP开发 ...