当前位置: 首页 > news >正文

3.上传图片(阿里云空间,oss验证)

 笔记

20240710   未验证,现在还没有阿里云空间,等买个sit环境就可以验证一下。

 前端

        页面
<!--页面-->
<el-form-item label="优惠券图片" prop="couponImg"><single-upload v-model="dataForm.couponImg"></single-upload>
</el-form-item><!--vue引入-->
import SingleUpload from "@/components/upload/singleUpload";<!--vue对象里加组件-->
components: { SingleUpload },<!--保存方法,couponImg就是url路径-->
        组件
<template> <div><!-- action必选参数,上传地址,bucket的外网访问域名 --><el-uploadaction="https://vivi-gulimall.oss-cn-hangzhou.aliyuncs.com":data="dataObj"list-type="picture":multiple="false" :show-file-list="showFileList":file-list="fileList":before-upload="beforeUpload":on-remove="handleRemove":on-success="handleUploadSuccess":on-preview="handlePreview"><el-button size="small" type="primary">点击上传</el-button><div slot="tip" class="el-upload__tip">只能上传jpg/png文件,且不超过10MB</div></el-upload><el-dialog :visible.sync="dialogVisible"><img width="100%" :src="fileList[0].url" alt=""></el-dialog></div>
</template>
<script>import {policy} from './policy'import { getUUID } from '@/utils'export default {name: 'singleUpload',props: {value: String},computed: {imageUrl() {return this.value;},imageName() {if (this.value != null && this.value !== '') {return this.value.substr(this.value.lastIndexOf("/") + 1);} else {return null;}},fileList() {return [{name: this.imageName,url: this.imageUrl}]},showFileList: {get: function () {return this.value !== null && this.value !== ''&& this.value!==undefined;},set: function (newValue) {}}},data() {return {dataObj: {policy: '',signature: '',key: '',ossaccessKeyId: '',dir: '',host: '',// callback:'',},dialogVisible: false};},methods: {emitInput(val) {this.$emit('input', val)},handleRemove(file, fileList) {this.emitInput('');},handlePreview(file) {this.dialogVisible = true;},beforeUpload(file) {let _self = this;return new Promise((resolve, reject) => {policy().then(response => {_self.dataObj.policy = response.data.policy;_self.dataObj.signature = response.data.signature;_self.dataObj.ossaccessKeyId = response.data.accessid;_self.dataObj.key = response.data.dir + getUUID() + '_${filename}';_self.dataObj.dir = response.data.dir;_self.dataObj.host = response.data.host;console.log("上传前请求服务端签名,得到结果:", _self.dataObj)resolve(true)}).catch(err => {reject(false)})})},handleUploadSuccess(res, file) {console.log("上传成功...")this.showFileList = true;this.fileList.pop();this.fileList.push({name: file.name, url: this.dataObj.host + '/' + this.dataObj.key.replace("${filename}",file.name) });this.emitInput(this.fileList[0].url);}}}
</script>
<style></style>

http://www.lryc.cn/news/396303.html

相关文章:

  • 仪表板展示|DataEase看中国:2023年中国新能源汽车经济运行情况分析
  • “Numpy数据分析与挖掘:高效学习重点技能“
  • 百川工作手机实现销售管理微信监控系统
  • RAG 工业落地方案框架(Qanything、RAGFlow、FastGPT、智谱RAG)细节比对!CVPR自动驾驶最in挑战赛赛道,全球冠军被算力选手夺走了
  • 华为防火墙 拓扑搭建1
  • Linux 利用命名空间创建一个自己的“容器“
  • RAG的学习与实践——LangChain和LlamaIndex学习笔记
  • Python爬虫原理以及3个小案例(源码)
  • Vagrant配合VirtualBox搭建虚拟机
  • Elasticsearch 建议(Suggesters):实现自动补全和拼写检查
  • 部署过docker后,防火墙firewall与iptables的基本指令
  • 华为 RIP 协议中 RIP 兼容版本、RIPv1、RIPv2 在收发 RIP 报文时的区别
  • 深度学习pytorch多机多卡网络配置桥接方法
  • 服务器信息获取工具
  • uniapp 防止重复提交数据
  • 线程池工具类
  • 印尼“支付宝” DANA 如何借力 OceanBase 实现3个“关键零”
  • 2018-2022 年份微博签到数据集
  • Avalonia开发实践(二)——开发带边框的Grid
  • Java泛型的定义与运用
  • Java如何自定义注解及在SpringBoot中的应用
  • 微软 Edge 浏览器全解析
  • C++ 八股(1)
  • 超高精电容传感器PCAP01调试+LABVIEW数据可视化调试手记
  • 5.更多
  • ConditionalOnJndi注解使用介绍、应用场景以及示例代码
  • Spring Cloud 引入
  • 自定义波形图View,LayoutInflater动态加载控件保存为本地图片
  • 每日一道算法题 求最小公倍数
  • 【OCC学习18】三维几何对象工具包:TKG3d