我不知道如何使用它,即使我有研究但它仍然无效
fs.rename(tmpFile, nFile, function(){
var stream = fs.createReadStream(nFile);
var req = knoxClient.putStream(stream, fName, {
'Content-type': 'image/jpeg',
'Content-Length': fSize
}, function(err, results){
console.log(results);
});
req.on('response', function(resX){
if(resX.statusCode == 200){
console.log("Pushed Success!!!!!!!!");
res.writeHead(200, {'Content-type': 'text/plain'});
res.end(JSON.stringify({"FileName": fName}));
}else{
var err = new Error("Error" + resX.statusCode);
err.status = resX.statusCode;
next(err);
}
});
});
最后,在createReadStream之前或之后使用gm(或im)?
答案 0 :(得分:0)
knox documentation
上有一个例子fs.stat('./Readme.md', function(err, stat){
// Be sure to handle `err`.
var req = client.put('/Readme.md', {
'Content-Length': stat.size
, 'Content-Type': 'text/plain'
});
fs.createReadStream('./Readme.md').pipe(req);
req.on('response', function(res){
// ...
});
});