上传静态文件代码:
@PostMapping("/test/upload")
public R iconUpload(@RequestBody MultipartFile file) {
String fileName = file.getOriginalFilename(); //原文件名
String suffixName = fileName.substring(fileName.lastIndexOf(".")); //文件后缀
String filePath = "/data/xxx/test/"; //上传后的路径
fileName = UUID.randomUUID() + suffixName; //新文件名
File dest = new File(filePath + fileName); //文件全路径名
if (!dest.getParentFile().exists()) {
dest.getParentFile().mkdirs();
}
try {
file.transferTo(dest);
} catch (IOException e) {
e.printStackTrace();
}
return R.ok("http://192.168.1.100:80/test/" + fileName);
}
============================================
nginx 配置访问图片 、文本地址
yum install -y nginx
systemctl enable nginx
systemctl start nginx
vi /etc/nginx/nginx.conf
server {
listen 80;
server_name localhost;
location /test/ {
alias /data/xxx/test/;
autoindex on;
}
}
location /prod/ {
alias /data/xxx/prod/;
autoindex on;
}
}
nginx -t
nginx -s reload
http://172.16.5.100/test/xxx.jpg