vant upload 上传七牛

2020-02-19 10:39:51 浏览数 (1)

代码语言:javascript复制
beforeRead (file) {
      return new Promise((resolve, reject) => {
        if (file.type !== 'image/jpeg') {
          let msg = '请上传 jpg 格式图片'
          Toast(msg)
          reject(msg)
        } else {
          token().then(res => {
            let data = new FormData()
            data.append('token', res.data.token)
            data.append('key', res.data.save_key)
            data.append('file', file)
            console.log(data)
            request({
              url: qiniuUploadUrl,
              method: 'POST',
              data: data,
              headers: {
                'Content-Type': 'multipart/form-data'
              }
            }).then(response => {
              this.fileList = [{
                url: res.data.domain   '/'   response.key,
                isImage: true
              }]
              resolve(response)
            })
          }).catch((error) => {
            console.log(error)
            reject(error)
          })
        }
      })
    },

0 人点赞