upload.js 970 Bytes
var request=require('request');
var fs=require('fs');
var domain = require('../../config/common.js').domain;

exports.uploadFile=function(req,res){
   
    // TODO 代理上传
    // 方法1
    // if(req.is("multipart/form-data")){
    //     req.body.file=fs.createReadStream(req.files[req.body.filename].path);
    //     request.post({url:domain+'/fileupload/upload',formData:req.body},function optionalCallback(err, httpResponse, body){
    //         res.json(JSON.parse(body));
    //     });
    // }else{
    //    res.json({code:"500",message:"请求类型错误"});
    // }
    res.json({
            "code":200,
            "data" : "https://ss1.baidu.com/6ONXsjip0QIZ8tyhnq/it/u=1444256491,538988776&fm=80",
            "message":"success"
        });
    
    //方法2
    // req.pipe(request.post(domain+'/fileupload/upload'))
    // .on('error', onerror)
    // .pipe(res);
    // function onerror(err) {
    //     console.error(err.stack)
    // }
}