0

生成了个二维码七牛上传成功,文件下载下来为空,0B

const qrImageStream = await fs.createReadStream(path.join(__dirname, `../../imageHandler/${apkName}_qrImage.png`));
console.log(qrImageStream);

// 上传qrImage至七牛
await qiniu.putFileToQiniu(`${apkName}_qrImage.png`, qrImageStream, true);

七牛:

const accessKey = config.qiniuConfig.accessKey;
const secretKey = config.qiniuConfig.secretKey;
const bucket = config.qiniuConfig.bucket;
const publicBucketDomain = config.qiniuConfig.publicBucketDomain;
const mac = new qiniu.auth.digest.Mac(accessKey, secretKey);
const qiniuConfig = new qiniu.conf.Config();
qiniuConfig.zone = qiniu.zone.Zone_z0;
const formUploader = new qiniu.form_up.FormUploader(qiniuConfig);
const putExtra = new qiniu.form_up.PutExtra();
const bucketManager = new qiniu.rs.BucketManager(mac, qiniuConfig);

/**
 * 上传七牛
 * @param  {Object}   key  [description]
 * @param readerStream
 * @param isImage
 * @return {[type]}        [description]
 */
exports.putFileToQiniu = async (key, readerStream, isImage) => {

  const options = {
    scope: bucket + ":" + key,
  };
  if (isImage) {
    options.detectMime = 1;
    options.mimeLimit = 'image/*';
  }
  const putPolicy = new qiniu.rs.PutPolicy(options);
  // 生成上传凭证
  const uploadToken = putPolicy.uploadToken(mac);
  // 上传文件
  return new Promise((resolve, reject) => {
    formUploader.putStream(uploadToken, key, readerStream, putExtra, function (respErr, respBody, respInfo) {
      if (respErr) {
        reject(respErr);
        throw respErr
      }
      if (respInfo.statusCode === 200) {
        resolve(respBody);
        console.log("success: ", key)
      }
    })
  });
};
2018-11-22 提问

1 个回答

0

我把文件命名改了就ok了。。。
后缀_qrImage.png改成_qr_image.png

你可能感兴趣的

推广链接