Last active
September 10, 2021 09:51
-
-
Save HDegroote/44bf3bfe919b0a473f4a52ca4ea5b4d6 to your computer and use it in GitHub Desktop.
Test server for uploading tensorflow models
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require('express') | |
var formidable = require('formidable') | |
util = require('util'); | |
const app = express() | |
const port = 3000 | |
app.listen(port, () => { | |
console.log(`Server listening at http://localhost:${port}`) | |
}) | |
//Form parsing from https://nodejs.org/en/knowledge/HTTP/servers/how-to-handle-multipart-form-data/ | |
app.post('/save_model', async (req, res) => { | |
var form = new formidable.IncomingForm(); | |
// form.parse analyzes the incoming stream data, picking apart the different fields and files for you. | |
form.parse(req, function(err, fields, files) { | |
if (err) { | |
// Check for and handle any errors here. | |
console.error(err.message); | |
return; | |
} | |
console.log(fields) | |
console.log(files) | |
res.writeHead(200, {'content-type': 'text/plain'}); | |
res.write('received upload:\n\n'); | |
// This last line responds to the form submission with a list of the parsed data and files. | |
res.end(util.inspect({fields: fields, files: files})); | |
}); | |
return; | |
}) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment