私はWebアプリケーションを設計しており、バックエンドシステムはExpress + Parse.Serverです。現在、私はParseサーバーで画像を保存する方法に問題があります。ここでNodejsでParse.comに画像を保存するには
は私EJSが
<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>
をファイルであり、これは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');
});
である私が手にこのエラーは次のとおりです。
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)
任意の助けが親切いただければ幸いです。ありがとう!
であなたは[0]のvar PIC = req.body.picで試してみます。 ? –
私はそれを試みたが、それはちょうど私の絵の名前の最初の単語を示しています – LaiTing
ねえ、これを解決するためにトゥを持っていますか?あなたがmulterをインストールした未定義 – bbkrz