I am designing a web application and backend system is Express + Parse.Server. Currently , I get the problem with how to deal with save the picture in my Parse server.
Here is my ejs file
<html>
<head>
<title>test</title>
</head>
<body>
<form action='/pictest' method='post'>
<h3>test</h3>
<input type="file" name="pic" id ="pict" >
<input type='submit' value='Submit'>
</form>
</body>
</html>
And this is the server.js
router.post('/pictest',function(req,res){
var pic = req.body.pic;
console.log(pic);
if (pic.length > 0) {
var file = new Parse.File("photo.jpg", pic, "image/png");
file.save().then(function() {
console.log("file save success");
res.end();
}, function(error) {
console.log("file save error " + error.message);
});
}
res.send('test');
});
This error I get is :
TypeError: Cannot create a Parse.File with that data.
at new ParseFile (C:\Users\Tim\Desktop\example
\JavascriftLinkParse\node_modules\parse\lib\node\ParseFile.js:131:15)
at C:\Users\Tim\Desktop\example\JavascriftLinkParse\routers\index.js:29:15
at Layer.handle [as handle_request] (C:\Users\Tim\Desktop\example
\JavascriftLinkParse\node_modules\express\lib\router\layer.js:95:5)
at next (C:\Users\Tim\Desktop\example
\JavascriftLinkParse\node_modules\express\lib\router\route.js:131:13)
at Route.dispatch (C:\Users\Tim\Desktop\example
\JavascriftLinkParse\node_modules\express\lib\router\route.js:112:3)
at Layer.handle [as handle_request] (C:\Users\Tim\Desktop\example
\JavascriftLinkParse\node_modules\express\lib\router\layer.js:95:5)
at C:\Users\Tim\Desktop\example
\JavascriftLinkParse\node_modules\express\lib\router\index.js:277:22
at Function.process_params (C:\Users\Tim\Desktop\example
\JavascriftLinkParse\node_modules\express\lib\router\index.js:330:12)
at next (C:\Users\Tim\Desktop\example
\JavascriftLinkParse\node_modules\express\lib\router\index.js:271:10)
at Function.handle (C:\Users\Tim\Desktop\example
\JavascriftLinkParse\node_modules\express\lib\router\index.js:176:3)
Any help would be helpfully appreciated. Thanks!
via LaiTing
No comments:
Post a Comment