1. 程式人生 > >微信公眾號圖片上傳接口

微信公眾號圖片上傳接口

0kb false name and ima primary 解決 bsp mar

結合elemen ui

 <el-upload
                      class="upload-demo"
                      :on-preview="handlePreview"
                      action="66666"
                        :on-remove="handleRemove"
                          multiple
                      :before-upload="shopbeforeAvatarUpload"
> <el-button size="small" type="primary" @click=‘getupload()‘>點擊上傳</el-button> <div slot="tip" class="el-upload__tip">只能上傳jpg/png文件,且不超過500kb</div> </el-upload>

跨越問題,下次再補上解決方法

getupload(){
                this.$http.put(wechatapi+‘/token?access-token=‘+this.token).then((res)=> {
                    
                    this.upload = ‘/cgi-bin/material/add_material?access_token=‘+ res.body+‘
&type=image‘; return }).catch((error)=> {}) }, shopbeforeAvatarUpload(file) { const isJPG = file.type === ‘image/jpeg/png‘; const isLt2M = file.size / 1024 / 1024 < 2; if (!isLt2M) { this.$message.error(‘上傳頭像圖片大小不能超過 2MB!‘); } this.$http.put(wechatapi+‘/token?access-token
=‘+this.token).then((res)=> { var fd =new FormData(); fd.append(‘media‘,file,file.name); this.$http.post(‘/cgi-bin/material/add_material?access_token=‘+ res.body+‘&type=image‘,fd,{emulateJSON:true}).then((res)=>{ console.log(res) }).catch((res)=>{}) }).catch((error)=> {}) return false },

另外獲取微信token的接口是封裝過的

微信公眾號圖片上傳接口