0

const uploadFileToQiNiu = (file) => {
return new Promise((resolve, reject) => {

const { buffer, originalname } = file
const accessKey = fileConfig.qiniu.accessKey
const secretKey = fileConfig.qiniu.secretKey
const bucket = fileConfig.qiniu.bucket
const mac = new qiniu.auth.digest.Mac(accessKey, secretKey)

const options = {
  scope: bucket + ":" + originalname,
}
const putPolicy = new qiniu.rs.PutPolicy(options)
const uploadToken = putPolicy.uploadToken(mac)

const qiniuConfig = new qiniu.conf.Config()
// 空间对应的机房
qiniuConfig.zone = qiniu.zone.Zone_z2
const formUploader = new qiniu.form_up.FormUploader(qiniuConfig)
const putExtra = new qiniu.form_up.PutExtra()
const readableStream = buffer // 可读的流
formUploader.putStream(uploadToken, originalname, readableStream, putExtra, (respErr,
  respBody, respInfo) => {
  console.log(respErr)
  if (respErr) {
    console.log(respErr)
    reject()
  }
  if (respInfo.statusCode == 200) {
    console.log(respBody);
    resolve()
  } else {
    console.log(respBody);
    reject()
  }
})

})
}

感觉不会进入formUploader.putStream()方法,无论成功还是失败,没有任何响应

licc 3
2019-02-26 提问
0 个回答

撰写答案

你可能感兴趣的

推广链接