Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Given the appropriate `columnType`, MySQL and PostgreSQL will handle storing buffers for you.
- ### Model
- ```js
- module.exports = {
- attributes: {
- name: {
- type: 'string',
- },
- avatar: {
- type: 'ref',
- columnType: 'mediumblob' // <-- for MySQL. Use `bytea` for PostgreSQL.
- }
- }
- };
- ```
- ### In `sails console`...
- ```
- sails> var image = fs.readFileSync('/path/to/image.png');
- sails> User.create({name: 'joe', avatar: image}).exec(console.log);
- ```
- ### To retrieve
- ```
- sails> User.findOne({name: 'joe'}).exec(function(err, user){ fs.writeFileSync('/new/file/path.png', user.avatar); });
- ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement