收藏
回答

公众号前端用vue开发的,使用await axios.post请在模拟器上没问题手机微信上运行出错?

async uploadImgToQiniu(file){
   return new Promise(async (resolve,reject)=>{
      //   const axiosInstance = axios.create({withCredentials: false});    //withCredentials 禁止携带cookie,带cookie在七牛上有可能出现跨域问题
      let url ="https://upload.qiniu.com" //这个上传的路径和调用接口获得的token值;
      let config ={
         headers:{'Content-Type':'multipart/form-data'}
      }

      let imgList=[];//定义存储file的数组
      if(file instanceof  Array){
         for(let i=0;i<file.length;i++){
            imgList = [...imgList,file[i].file]
         }
      }else{
         imgList =[...imgList,file.file]
      }
      let projectimg =[];
      //遍历数组
      for(let i=0;i<imgList.length;i++){
         let formData = new FormData();
         formData.append('token', this.token);     //七牛需要的token,叫后台给,是七牛账号密码等组成的hash
         formData.set('file',imgList[i]);//这里要用set,如果用append,还是会出现一起上传的情况
         // console.log(formData.get("file")
         let result  = await axios.post(url,formData,config)
         // let result  = request.post(url,formData,config)
         let images='http://qn.xxxx.com/'+result.data.key; //上传成功...  (登录七牛账号,找到七牛给你的 URL地址) 和 data里面的key 拼接成图片下载地址
         alert(images)
         projectimg.push(images) ;
      }
      resolve(projectimg)
   })
},


回答关注问题邀请回答
收藏

2 个回答

  • 游戏人生
    游戏人生
    2020-07-19

    建议你把什么错贴出来,就是报错的信息和截图

    不然官方很难帮得了你啊

    2020-07-19
    有用
    回复
  • 回故里
    回故里
    2020-07-19

    没有官方支持吗

    2020-07-19
    有用
    回复
登录 后发表内容
问题标签