javascript - How to upload files using nodejs and HAPI? -
Can anyone tell me how to upload files using NodeJS and HAPI?
I'm getting inside the binary data headler.
This is my html code:
function sendFormFromHTML (form) {// form = $ ("UploadForm"). Form; Var formatta = new form data (form); FormData.append ('id', '123456'); // Option for hidden areas var xhr = new XMLHttpRequest (); Xhr.open ('post', form.action, true); Xhr.onload = function (e) {warning (this.responsetext)}; Xhr.send (formData); return false; } & Lt; Form method = "post" id = "uploadform" action = "http: // localhost: 3000 / api / uploadfiles" enquepe = "multipart / form-data" & gt; & Lt; Label = "upload" & gt; File (binary): & lt; / Label & gt; & Lt; Input type = "file" name = "upload" class = "file upload" /> gt; & Lt; Br / & gt; & Lt; Input type = "button" class = "submit" value = "submit" onclick = "sendFormFromHTML (this.form);" /> & Lt; / Form & gt; Here is my NodeJS code: server.route ({Method: 'POST', path: '/ API / uploadfiles', config: { Handler: current position .uploadFiles,}}); Upload Files: Function (Request, Answer) {console.log (req.payload); }
For new readers, hpy is already using multifunction It is from the haptic documentation to handle multipart post requests; If the payload is 'multipart / form-data' and the parse is true, the field values are presented as text, whereas the files are provided as streams. File streams with a 'multiparty / form-data' upload will also have an asset HAPI with file name and header property
example;
server.route ({method: 'POST', path: '/ create', config: {payload: {maxBytes: 209,715,200, production: 'stream', pars: true}, handler :, Function (request reply) {request.payload ["HtmlInputName"]. Pipe (fs.createWriteStream ("test"));}});
Comments
Post a Comment