Created
November 18, 2018 21:22
-
-
Save zcaceres/2e24a272bc30978489e251858bc90983 to your computer and use it in GitHub Desktop.
Sample 2
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
... | |
// 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