2017-05-03 8 views
0

私は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) 

任意の助けが親切いただければ幸いです。ありがとう!

+1

であなたは[0]のvar PIC = req.body.picで試してみます。 ? –

+0

私はそれを試みたが、それはちょうど私の絵の名前の最初の単語を示しています – LaiTing

+0

ねえ、これを解決するためにトゥを持っていますか?あなたがmulterをインストールした未定義 – bbkrz

答えて

0

あなたは急行

multerを使用することができますし、コントローラ

var buffer = req.files.pic[0].buffer; 
var base64 = buffer.toString('base64'); 
var name = "pic_name"; 
var file = new Parse.File(name, { base64: base64 }); 
+0

こんにちは、アルトゥーロ私はあなたのメソッドを使用してmulterは を表現参照しようとしました そして、それ持っていた別のエラー はTypeError? – LaiTing

+0

のプロパティを読み取ることができません「PIC」:私は..同じような状況にいるよ –