我尝试了这个程序,但是当我从app.can收到图像时,我在服务器端遇到了意外的字段错误,任何人都解决了这个问题。我在等你的回复。提前谢谢......
nodejs code:
var express=require("express");
var bodyparser=require("body-parser");
var multer=require("multer");
var fs=require("fs");
var app=express();
var upload = multer({ dest: '/tmp/'});
app.use(bodyparser.urlencoded({extended:false}));
app.post("/uploadimage",upload.single("file"),function(request,response)
{
console.log("I got a request");
var filepath=__dirname+"/imagesfolder/beta.jpg";
fs.readFile(request.file.path,function(err,data)
{
if(err)
{
console.log(err);
}
else
{
fs.writeFileSync(filepath,data);
console.log("successfully stored");
}
});
});
app.listen(8086,function()
{
console.log("server running on port 8086");
});