node端 七牛上传成功,文件下载下来为空,0B

生成了个二维码七牛上传成功,文件下载下来为空,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)
      }
    })
  });
};
阅读 3.1k
2 个回答
✓ 已被采纳新手上路,请多包涵

上传策略增加大小限制
参考:看这里

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

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
logo
七牛云问答
子站问答
访问
宣传栏