Skip to content

Instantly share code, notes, and snippets.

@zcaceres
Created November 18, 2018 21:22
Show Gist options
  • Save zcaceres/2e24a272bc30978489e251858bc90983 to your computer and use it in GitHub Desktop.
Save zcaceres/2e24a272bc30978489e251858bc90983 to your computer and use it in GitHub Desktop.
Sample 2
...
// Our prediction endpoint (Receives an image as req.file)
app.post('/predict', upload.single('img'), async function (req, res) {
const { path } = req.file
try {
const prediction = await PythonConnector.invoke('predict_from_img', path);
res.json(prediction);
}
catch (e) {
console.log(`error in ${req.url}`, e);
res.sendStatus(404);
}
// delete the uploaded file (regardless whether prediction successful or not)
fs.unlink(path, (err) => {
if (err) console.error(err)
console.log('Cleaned up', path)
})
})
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment