beego文件上传服务器,7-Beego图片上传

上一篇文章和本篇文章讲解的都是业务逻辑,有异曲同工之妙.就像在一个控制系统中,需要有传感器接收信号,将接收的信号交给控制器,控制器控制执行器执行.这里,我们通过页面拿到用户输入的数据,交给控制器作相应的处理,然后控制器控制页面跳转/报错/并拿到用户的数据存储到数据库,这么说,是不是简单多了呢.下面为了让大家觉得更简单,我会提供简单的两张图示,让大家之后的功能开发思路更加清晰.在所有知识点掌握之后,剩下我们要做的就是在心中搭建起那条纵横交错的小路,今天有点啰嗦,哈哈哈哈哈哈,大概是看到自己离搭建网站又更近了一步吧

f1adf62c9c7f?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation

传感器业务逻辑.png

f1adf62c9c7f?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation

Beego项目流程.png

我们在第一篇文章就讲了beego的项目执行流程,只是这一路学习下来对它应该有更深刻的认识

一.图片上传-index.html

我们需要一个index页面,实现各个功能界面的跳转,就像网页导航一样,有了它,我们就能快速访问我们想访问的界面;就像字典的目录,公园的地图

f1adf62c9c7f?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation

image.png

f1adf62c9c7f?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation

image.png

f1adf62c9c7f?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation

image.png

二.图片上传-add.html

f1adf62c9c7f?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation

image.png

三.图片上传-AddController.go

f1adf62c9c7f?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation

效果图.gif

f1adf62c9c7f?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation

image.png

f1adf62c9c7f?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation

image.png

f1adf62c9c7f?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation

image.png

f1adf62c9c7f?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation

image.png

f1adf62c9c7f?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation

image.png

f1adf62c9c7f?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation

image.png

四.图片上传-models.go

f1adf62c9c7f?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation

image.png

f1adf62c9c7f?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation

image.png

f1adf62c9c7f?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation

image.png

保存View传递过来的文件

第一个参数: View传递数据时指定的key

第二个参数: 需要将文件保存到什么地方

By 极客江南

五.图片上传-解决图片重名覆盖问题

注意点:

在企业发开中要注意文件名称重名问题, 后上传的会覆盖先上传的

一般会按照天来创建文件夹

一般会给文件添加前缀

By 极客江南

企业开发中,一般会一天换一个路径,并且给每一张上传的图片添加时间前缀,就像webpack中的css loader一样

f1adf62c9c7f?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation

image.png

f1adf62c9c7f?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation

image.png

添加上时间前缀就不会出现重名覆盖的问题了

这里企业开发中,实际上是一天一个文件夹

但是这里不支持dirName+"/"+fileName的语法,不过这都是小问题

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值