请教服务端七牛上传的问题
发布于 19天前 作者 luoyjx 252 次浏览 来自 问答

我用的是 @fengmk2qn模块。 问题: 为何我在本地上传的时候可以成功,而放到阿里云centos上就一直报

urllib:warn Wed Jan 21 2015 21:47:01 GMT+0800 (CST) [worker:8774] POST http://up.qiniu.com/ callback twice!!!

这个错?

以下是代码:

exports.doUpload = function(req, res){ //console.log(req.files); if(req.files[‘imgFile’].size == 0){ //使用同步方式删除一个文件 fs.unlinkSync(req.files[i].path); console.log(' Successsfully removed an empty file!’); } else { var target_path = ‘./public/upload/’ + req.files[‘imgFile’].name; console.log(target_path); //使用同步方式重命名一个文件 var readStream = fs.createReadStream(req.files[‘imgFile’].path); var writeStream = fs.createWriteStream(target_path); readStream.pipe(writeStream, function(){ fs.unlinkSync(req.files[i].path); }); var client = qn.create({ accessKey: qiniu_config.AK, secretKey: qiniu_config.SK, bucket: 'my bucket’, domain: ‘my domain’ }); client.uploadFile(target_path, {key: ‘img/’ + req.files[‘imgFile’].name}, function (err, result) { console.log(result); if(result && result.url){ res.write(JSON.stringify({ “error” : 0, “url” : result.url })); console.log(“上传成功!”); }else{ res.write(JSON.stringify({ “error” : 1, “message” : “上传失败” })); console.log(“上传失败!”); } req.flash(‘success’,’文件上传成功!’); res.end(); }); } };

求各位大神指点~

回到顶部