java - Creating a HTTP Server in Node.js service POST with file -
i order sent post request parameter in form of jpg file.
i use httpclient in version 4.4.1
part of java code looks this:
closeablehttpclient httpclient = httpclients.createdefault(); try { file file = new file("path_to_jpg"); httppost post = new httppost("http://localhost:1337/uploadjpg"); filebody filebody = new filebody(file); multipartentitybuilder builder = multipartentitybuilder.create(); builder.setmode(httpmultipartmode.browser_compatible); builder.addpart("upfile", filebody); httpentity entity = builder.build(); post.setentity(entity); httpresponse response = httpclient.execute(post); system.out.println(response.getentity().getcontent()); } { httpclient.close(); } next @ "http://localhost:1337/uploadjpg" want let nodejs have server process jpg file
the idea of server code nodejs:
var http = require('http'), fs = require('fs'), server = http.createserver( function(req, res) { if (req.method == 'post') { //process file jpg res.writehead(200, {'content-type': 'text/html'}); res.end('processed jpg'); } }); port = 1337; host = '127.0.0.1'; server.listen(1337, '127.0.0.1'); console.log('listening @ http://' + '127.0.0.1' + ':' + 1337); and question is, how can create such service in nodejs, have file in jpg?
not sure if using express or not if you can use middleware multer makes simple handle multipart data , files.
Comments
Post a Comment