生成了个二维码七牛上传成功,文件下载下来为空,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)
}
})
});
};
上传策略增加大小限制
参考:看这里