type
status
date
slug
summary
tags
category
icon
password
Web开发中支持用户上传图片并显示出来是不可或缺的一个功能,下面讲解springboot项目如何接受前端上传的图片并返回图片url
springboot项目
- application.yml 添加配置
- FileUtil 上传文件工具类
为了防止上传的图片有重名,把接收到的文件名替换成一个不会重复的UUID(url会使用这个独特的UUID),然后把接收到的图片文件保存到目标目录下面。
- Controller
nginx反向代理
我们的项目代码实际上是将用户上传的图片保存在指定路径的文件夹下(需要在服务器创建好文件夹,此处为
/home/rainnn/photos/
我们想让用户在访问http://服务器地址/view/images/xxx时能够访问到服务器中的图片,需要使用nginx做反向代理,操作如下:
修改文件:
/etc/nginx/conf.d
nginx
即可运行nginx(在路径/etc/nginx
下)80端口如果被占用可以更换nginx的端口,或者使用以下命令
- Author:Rainnn
- URL:https://blog.rainnn.top//article/0f78595c-073f-41d4-a23f-d5a07582cd02
- Copyright:All articles in this blog, except for special statements, adopt BY-NC-SA agreement. Please indicate the source!
Relate Posts