1

我使用管道方法保存前端psss的文件,当我将本地保存的文件上传到云服务时,我不确定文件是否流完成,所以如何等待管道完成,然后上传该文件到云服务,最后返回响应

我也尝试编写将文件上传到云服务的步骤,但它不起作用

res.on('完成',function(){

...
})

        var koa-router = require("koa-router");
        var thunkify =require("thunkify");
        var parse = require("co-busboy");

        var parts = parse(this);  // "this" => request 

        while (part = yield parts){

            var imgPath = path.join(__dirname, "../../runtime/img_tmp", new Date().getTime() + "_" + part.filename.toString());
            stream = fs.createWriteStream(imgPath);
            res= part.pipe(stream);
        }
        //check and console.log the file is exist or not
        // upload to cloud service
        console.log(fs.existsSync(imgPath) || path.existsSync(imgPath));

        if(fs.existsSync(imgPath) || path.existsSync(imgPath)){

            var keyName = 'news/image/banner' + imgPath;

            var fileUpload_thunk = thunkify(awsUpload.fileUpload);
            yield fileUpload_thunk(fs.createReadStream(imgPath), keyName);

            console.log(photoUrl);
            //put url to photoUrl 
            photoUrl = 'http://goappdl.goforandroid.com/' + keyName;
            console.log("data-amazionFinished:"+new Date().getTime());
        }
        this.body={"state":1,"url":photoUrl}
4

0 回答 0