国产亚洲精品福利在线无卡一,国产精久久一区二区三区,亚洲精品无码国模,精品久久久久久无码专区不卡

當(dāng)前位置: 首頁(yè) > news >正文

鄭州seo網(wǎng)站排名優(yōu)化公司蘇州網(wǎng)站建設(shè)開(kāi)發(fā)公司

鄭州seo網(wǎng)站排名優(yōu)化公司,蘇州網(wǎng)站建設(shè)開(kāi)發(fā)公司,深圳龍崗企業(yè)網(wǎng)站建設(shè),昆明網(wǎng)站建站平臺(tái)1、首先登錄騰訊云官網(wǎng)控制臺(tái) 進(jìn)入對(duì)象存儲(chǔ)頁(yè)面 2、找到跨越訪問(wèn)CIRS設(shè)置 配置規(guī)則 點(diǎn)擊添加規(guī)則 填寫信息 3、書寫代碼 這里用VUE3書寫 第一種用按鈕出發(fā)事件形式 <template><div><input type"file" change"handleFileChange" /><…

1、首先登錄騰訊云官網(wǎng)控制臺(tái) 進(jìn)入對(duì)象存儲(chǔ)頁(yè)面

2、找到跨越訪問(wèn)CIRS設(shè)置 配置規(guī)則

?點(diǎn)擊添加規(guī)則

?填寫信息

?3、書寫代碼

這里用VUE3書寫

第一種用按鈕出發(fā)事件形式

<template><div><input type="file" @change="handleFileChange" /></div>
</template><script>
import COS from "cos-nodejs-sdk-v5"; // 導(dǎo)入cos-nodejs-sdk-v5包export default {methods: {handleFileChange(event) {const file = event.target.files[0];const cos = new COS({SecretId: "YOUR_SECRET_ID",SecretKey: "YOUR_SECRET_KEY",});// 替換成你的 Bucket 名稱和 Regionconst bucket = "YOUR_BUCKET_NAME";const region = "YOUR_BUCKET_REGION";// 生成對(duì)象存儲(chǔ)桶中的圖片路徑const key = `images/${file.name}`;// 將圖片上傳到騰訊云對(duì)象存儲(chǔ)桶cos.putObject({Bucket: bucket,Region: region,Key: key,Body: file,},(err, data) => {if (err) {console.error("上傳失敗:", err);this.$message.error("上傳失敗")} else {console.log("上傳成功:", data.Location);this.$message.success("上傳成功")}});},},
};
</script>

4、測(cè)試

點(diǎn)擊選擇文件

選擇圖片?

等待結(jié)果

?

第二種用el-upload

<el-upload v-if="imageUrl===null"class=""list-type="picture-card":show-file-list="false":before-upload="beforeUpload"action="":on-change="handleUploadChange"><el-icon class="el-icon-plus"><plus></plus></el-icon>
</el-upload>
beforeUpload(file) {// 預(yù)覽圖片this.file = file;this.imageUrl = URL.createObjectURL(file);console.log("頭像鏈接為"+this.imageUrl)return new Promise((resolve, reject) => {const cos = new COS({SecretId: "", // 身份識(shí)別 IDSecretKey: "", // 身份密鑰});// 替換成你的 Bucket 名稱和 Regionconst bucket = "";const region = "";// 生成對(duì)象存儲(chǔ)桶中的圖片路徑const key = `user_information/avatar/${this.user.username}/${file.name}`;let key1='';console.log("key為"+key)// 將文件轉(zhuǎn)換為 Blob 對(duì)象const blob = new Blob([file.raw], { type: file.type });console.log("blob"+blob)// 將圖片上傳到騰訊云對(duì)象存儲(chǔ)桶cos.putObject({Bucket: bucket,Region: region,Key: key,Body: file,},(err, data) => {setTimeout(()=>{if (err) {console.error("上傳失敗:", err);this.$message.error("上傳失敗");reject(err);} else {// console.log("打撒筆"+this.user.avatarUrl)console.log("上傳成功:", data.Location);if(this.user.avatarUrl!==null){key1 = this.user.avatarUrl.replace("https://"+bucket+".cos."+region+".myqcloud.com/", "");// 刪除文件console.log("key1:", key1);cos.deleteObject({Bucket: bucket,Region: region,Key: key1,}, (err, data) => {if (err) {console.log('Error deleting file:', err);} else {console.log(data)console.log('云端路徑為:'+key1+"的圖片已經(jīng)被刪除");}});}this.form.avatarUrl="https://"+ data.Locationthis.user.avatarUrl="https://"+ data.LocationlocalStorage.setItem("user", JSON.stringify(this.user));// 刷新當(dāng)前頁(yè)面location.reload();this.save1();console.log(data)// this.$message.success("上傳圖片成功");resolve(false); // 阻止 Element-UI 的默認(rèn)上傳行為}},1000)});// if(key1!==''){// }});},

也可以把el-upload嵌套button包裝成這種形式

<el-uploadclass="":show-file-list="false":before-upload="beforeUpload"action="":on-change="handleUploadChange"style="margin-right: 15px"><el-button v-if="this.user.avatarUrl"  style="background-color: #3f72af;color: white;border-radius: 15px;width: 100px;height: 40px" type="" >更改頭像</el-button> 
</el-upload>

按照這個(gè)邏輯上傳頭像的整體代碼 (寫的不好 待優(yōu)化 歡迎大神優(yōu)化)

<div v-if="this.user.avatarUrl" class="avatar"><el-image id="elimg"  class="preview-image":src="this.user.avatarUrl"style="width: 170px; height: 170px; position: relative; justify-content: center" ></el-image ></div><div v-else class="avatar" id="avatar"><el-image id="elimg" v-if="imageUrl" class="preview-image":src="imageUrl":preview-src-list="[imageUrl]" style="width: 170px; height: 170px; position: relative; justify-content: center" ></el-image ><el-icon size="large"  v-if="imageUrl" class="el-icon-close" @click="cancelUpload"><close></close></el-icon><el-upload v-if="imageUrl===null"class=""list-type="picture-card":show-file-list="false":before-upload="beforeUpload"action="":on-change="handleUploadChange"><el-icon class="el-icon-plus"><plus></plus></el-icon></el-upload></div>
import {Close, Plus} from "@element-plus/icons";
import COS from "cos-js-sdk-v5";export default {name: "UserInfo",components: {Plus,Close},data(){return {form:{},user: localStorage.getItem("user") ? JSON.parse(localStorage.getItem("user")):{},imageUrl: null,file: null,}},}
 beforeUpload(file) {// 預(yù)覽圖片this.file = file;this.imageUrl = URL.createObjectURL(file);console.log("頭像鏈接為"+this.imageUrl)return new Promise((resolve, reject) => {const cos = new COS({SecretId: "", // 身份識(shí)別 IDSecretKey: "", // 身份密鑰});// 替換成你的 Bucket 名稱和 Regionconst bucket = "";const region = "";// 生成對(duì)象存儲(chǔ)桶中的圖片路徑const key = `user_information/avatar/${this.user.username}/${file.name}`;let key1='';console.log("key為"+key)// 將文件轉(zhuǎn)換為 Blob 對(duì)象const blob = new Blob([file.raw], { type: file.type });console.log("blob"+blob)// 將圖片上傳到騰訊云對(duì)象存儲(chǔ)桶cos.putObject({Bucket: bucket,Region: region,Key: key,Body: file,},(err, data) => {setTimeout(()=>{if (err) {console.error("上傳失敗:", err);this.$message.error("上傳失敗");reject(err);} else {// console.log("打撒筆"+this.user.avatarUrl)console.log("上傳成功:", data.Location);if(this.user.avatarUrl!==null){key1 = this.user.avatarUrl.replace("https://"+bucket+".cos."+region+".myqcloud.com/", "");// 刪除文件console.log("key1:", key1);cos.deleteObject({Bucket: bucket,Region: region,Key: key1,}, (err, data) => {if (err) {console.log('Error deleting file:', err);} else {console.log(data)console.log('云端路徑為:'+key1+"的圖片已經(jīng)被刪除");}});}this.form.avatarUrl="https://"+ data.Locationthis.user.avatarUrl="https://"+ data.LocationlocalStorage.setItem("user", JSON.stringify(this.user));// 刷新當(dāng)前頁(yè)面location.reload();this.save1();console.log(data)// this.$message.success("上傳圖片成功");resolve(false); // 阻止 Element-UI 的默認(rèn)上傳行為}},1000)});// if(key1!==''){// }});},cancelUpload() {// 清除預(yù)覽圖片和文件this.imageUrl = null;this.file = null;},save1(){this.request.post("/saveuser",this.form).then(res => {if(res){this.$message.success("保存圖片成功")}else{this.$message.error("保存圖片成功")}})},

http://aloenet.com.cn/news/28247.html

相關(guān)文章:

  • 優(yōu)化是企業(yè)通過(guò)網(wǎng)站來(lái)做嗎天津seo關(guān)鍵詞排名優(yōu)化
  • 嘉興的信息公司網(wǎng)站怎么做網(wǎng)站平臺(tái)
  • 企業(yè)網(wǎng)站的需求分析精準(zhǔn)客戶數(shù)據(jù)采集軟件
  • 做文案用什么網(wǎng)站宣傳推廣方式有哪些
  • 做網(wǎng)站解析要多久百度應(yīng)用商店app下載安裝
  • php做視頻網(wǎng)站有哪些軟件下載方象科技的企業(yè)愿景
  • 臨沂網(wǎng)站建設(shè)有哪些啥是網(wǎng)絡(luò)推廣
  • 專業(yè)地推團(tuán)隊(duì)seo百度快速排名軟件
  • 沒(méi)有網(wǎng)站限制的瀏覽器臺(tái)州網(wǎng)站建設(shè)
  • 汕頭網(wǎng)絡(luò)公司網(wǎng)站建設(shè)朝陽(yáng)網(wǎng)站seo
  • 做烘培的網(wǎng)站有哪些b2b網(wǎng)站推廣優(yōu)化
  • 什么網(wǎng)站做優(yōu)化最好外貿(mào)網(wǎng)站平臺(tái)哪個(gè)好
  • 企業(yè)發(fā)展歷程網(wǎng)站關(guān)鍵詞優(yōu)化怎么操作
  • 恐怖音樂(lè)怎么做的視頻網(wǎng)站公司網(wǎng)絡(luò)營(yíng)銷推廣方案
  • 電商網(wǎng)站開(kāi)發(fā)教材唐山seo
  • 學(xué)院網(wǎng)站建設(shè)管理規(guī)章制度谷歌瀏覽器官網(wǎng)入口
  • 網(wǎng)站開(kāi)發(fā)功能需求表下載班級(jí)優(yōu)化大師并安裝
  • 煙臺(tái)中企動(dòng)力提供網(wǎng)站建設(shè)游戲推廣論壇
  • 做設(shè)計(jì)的都用那些網(wǎng)站seo基礎(chǔ)知識(shí)
  • 推廣型網(wǎng)站建設(shè)電話百度開(kāi)戶需要什么資質(zhì)
  • 漯河企業(yè)網(wǎng)站建設(shè)公司軟文廣告示范
  • 英文書 影印版 網(wǎng)站開(kāi)發(fā)廈門人才網(wǎng)個(gè)人會(huì)員
  • 中國(guó)那個(gè)公司的網(wǎng)站做的最好看有什么平臺(tái)可以推廣
  • 菏澤建設(shè)局網(wǎng)站網(wǎng)絡(luò)視頻營(yíng)銷平臺(tái)
  • 招商加盟類網(wǎng)站模板網(wǎng)站建設(shè)費(fèi)用
  • 手機(jī)做網(wǎng)站用什么軟件灰色詞排名推廣
  • 微小店網(wǎng)站建設(shè)平臺(tái)網(wǎng)絡(luò)營(yíng)銷推廣方案策劃
  • 做網(wǎng)站的要花多少錢推廣普通話作文
  • 低價(jià)網(wǎng)站建設(shè)行業(yè)現(xiàn)狀win10優(yōu)化軟件哪個(gè)好
  • 徐州網(wǎng)站優(yōu)化品牌宣傳如何做