当前位置:网站首页>Take out system file upload
Take out system file upload
2022-07-28 04:42:00 【Why not sell egg cakes well】
04 Upload files
/** * File upload and download */
@Slf4j
@RestController
@RequestMapping("/common")
public class CommonController {
@Value("${reggie.path}")
private String basePath;
@PostMapping("/upload")
public String upload(MultipartFile file){
log.info(file.toString());
// Original filename
String originalFilename = file.getOriginalFilename();
String suffix = originalFilename.substring(originalFilename.lastIndexOf("."));
// Use uuid Regenerate file name
String fileName = UUID.randomUUID().toString() + suffix;
// Create directory objects
File dir = new File(basePath);
// Determine whether the directory exists
if(!dir.exists()){
// directory does not exist , Need to create
dir.mkdirs();
}
try{
// Transfer the temporary file to the specified location
file.transferTo(new File(basePath+"hello.jpg"));
}catch (IOException ex){
ex.printStackTrace();
}
return fileName;
}
/** * File download */
@GetMapping("/download")
public void download(String name, HttpServletResponse response){
try{
// Input stream
FileInputStream fileInputStream = new FileInputStream(new File(basePath + name));
// Output stream
ServletOutputStream outputStream = response.getOutputStream();
response.setContentType("image/jpeg");
int len=0;
byte[] bytes=new byte[1024];
while ((len=fileInputStream.read(bytes))!=-1){
outputStream.write(bytes,0,len);
outputStream.flush();
}
// close resource
outputStream.close();
fileInputStream.close();
}catch (Exception e){
e.printStackTrace();
}
}
}
边栏推荐
- String 0123456789abcdef, what is the number of substrings (not empty and not the same string itself) [Hangzhou multi tester] [Hangzhou multi tester _ Wang Sir]
- Space complexity calculation super full sorting!! (calculation of hand tearing complexity
- 【sylar】框架篇-Chapter11-Socket 模块
- Important SQL server functions - numeric functions
- 重要的 SQL Server 函数 - 其他函数
- np. unravel_ Index() finds the index value of an element (or group of elements) of the array after being pulled into one dimension. The corresponding index value in the original dimension (or specify
- 01-Node-Express系统框架搭建(express-generator)
- Geely AI interview question [Hangzhou multi tester] [Hangzhou multi tester _ Wang Sir]
- Practice and thinking of AI standardization engine in pink client
- Simple summary of Modbus Protocol
猜你喜欢

Reading of seq2path: generating sentimental tuples as paths of a tree
![[idea] check out master invalid path problem](/img/83/d36362ba314177cd6f1f74f3e922cd.png)
[idea] check out master invalid path problem

Practice and thinking of AI standardization engine in pink client

Introduction to this pointer

ADB environment configuration

Render the data obtained from the database to the table in elementui

【Oracle】083错题集

How to upgrade a pair of 12.2 RAC(primary) and a pair of 12.2 RAC(dataguard) to 19c

Information system project manager (2022) - key content: information system integrated testing and management, project management maturity model, quantitative project management (21)

Odoo action analysis (action.client, action.act_window, action.server)
随机推荐
Ma Yi, Shen Xiangyang, Cao Ying's latest AI overview is hot! It took 3 months to build, netizens: required papers
Introduction to this pointer
Wang Shuang assembly language detailed learning notes 3: registers (memory access)
Solana「迷惑行为」:造手机、开门店
set与list性能对比
Advanced architects, 16 common principles of microservice design and Governance
【sylar】框架篇-Chapter15-Stream 模块
High number_ Chapter 4__ Curvilinear integral_ Exercise solution
25 openwrt guest network add
字符串0123456789abcdef,子串(非空且非同串本身)的个数是多少【杭州多测师】【杭州多测师_王sir】...
机器人教育在STEM课程中的设计研究
MySQL: data types and operators
Jupyter Notebook安装代码提示功能
[Sylar] framework -chapter15 stream module
MySQL数据库————初识数据库
【二、移动web网页开发】2D&3D转换与动画、移动端布局、响应式布局
网络安全基本知识——密码(一)
Machine learning and deep learning -- normalization processing
[Sylar] framework -chapter20- daemon module
Explain initialization list