Created
June 1, 2020 19:17
-
-
Save danizavtz/7acb7f6edc4d07e7b8dc2fc75e39455e to your computer and use it in GitHub Desktop.
image
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
CREATE TABLE IF NOT EXISTS media_file( | |
id SERIAL PRIMARY KEY, | |
img BYTEA, | |
mimetype VARCHAR(15), | |
media INT REFERENCES media(id) ON DELETE CASCADE | |
); |
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
exports.addFile = async(req, res) => { | |
let sql = 'INSERT INTO media_file(media, mimetype, img) VALUES ($1, $2, $3) returning *'; | |
try { | |
const result = await postgres.client.query(sql, [req.body.media, req.file.mimetype, req.file.buffer]); | |
res.status(201).json(result.rows[0]); | |
res.end(); | |
} catch (err) { | |
return res.status(500).json({ errors: [{ param: undefined, msg: err.detail, value: undefined }] }); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment