oss

    let file = { uri: image.path, type: 'multipart/form-data', name: 'image.png' }
    let fileName = new Date().getTime() + image.filename
    let filePath = 'headImg/' + fileName;
    let request = new FormData()
    request.append('accessKeyId', '*********')
    request.append('accessKeySecret', '*********************')
    request.append('endpoint', 'oss-cn-****.aliyuncs.com')
    request.append('bucket', '******')
    request.append('key', filePath)
    request.append('file', file)
    axios.post('http://*****.oss-cn-****.aliyuncs.com',
      request,
      { headers: { 'Content-Type': 'multipart/form-data' } }
    ).then((response) => {
      let headImgurl = 'http://*****.oss-cn-******.aliyuncs.com/' + filePath
      axios.post('修改头像',
        qs.stringify({
          headImgurl: headImgurl
        })
      ).then((response) => {
        Toast.info('修改成功', 1)
     }).catch((error) => {
        Toast.info('修改失败', 1)
      })
    }).catch((error) => {
      Toast.info('上传失败', 1)
      console.log(error)
    })

你可能感兴趣的:(oss)