I'm using an easy library called HappyHTTP in my C++ project (link to the lib : https://github.com/Zintinio/HappyHTTP)
I want to send a file to my nodejs server.
my javascript code is as follows :
var multer = require('multer');
var upload = multer({ dest: 'uploads/' });
router.post('/dicomPost',upload.single('dicom'),function (req,res) {
res.send(200);
})
and this is my C++ code :
happyhttp::Connection conn( "127.0.0.1", 3000 );
conn.setcallbacks( OnBegin, OnData, OnComplete, 0 );
conn.putrequest( "POST", "/dicomPost" );
conn.putheader( "Connection", "close" );
conn.putheader( "Content-Length", l);
conn.putheader( "Content-type", "multipart/form-data" );
conn.putheader("Content-Disposition","name=dicom; filename=test.txt");
conn.putheader( "Accept", "text/plain" );
conn.endheaders();
while( conn.outstanding() )
conn.pump();
from my C++ side, I can send body data but when it comes to a file , I'm getting a 500 Internal Server Error),please can anyone has a look at the github link above and see why my code is not working. I don't want to use libcurl because it's large, I just want to make a post with a lightwheight library as HappyHttp.
thank you in advance.
答案 0 :(得分:0)
问题出在服务器端,因此请检查服务器日志以查看是否有任何线索。我的猜测是uploads文件夹上的权限问题阻止你的javascript在那里写任何文件。