七牛雲上傳

https://github.com/qiniu/js-sdk

async uploadMainImg(imgName) {
      let file = event.target.files[0];
      if (!file) {
        return
      }
      let fille_key = Math.random()
        .toString(36)
        .substr(2)
        .toLocaleLowerCase();
      let self = this;
      let resData = await ajaxTool.Post("/taobao/get_img_url");
      let qn_token = resData.data.qny_token;
      let domain = resData.data.img_domain;
      if (resData.code == 1) {
        window.location.href = resData.data.url;
      }
      let config = {
        useCdnDomain: true
      };
      let putExtra = {
        fname: file,
        params: {},
        mimeType: ["image/png", "image/jpeg", "image/gif"]
      };
      let observe = {
        next(res) {},
        error(err) {},
        complete(res) {
          self[imgName] = domain + res.key;
        }
      };
      let observable = qiniu.upload(
        file,
        fille_key,
        qn_token,
        putExtra,
        config
      );
      let subscription = observable.subscribe(observe);
    },

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章