Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. Given the appropriate `columnType`, MySQL and PostgreSQL will handle storing buffers for you.
  2.  
  3. ### Model
  4.  
  5. ```js
  6. module.exports = {
  7. attributes: {
  8. name: {
  9. type: 'string',
  10. },
  11. avatar: {
  12. type: 'ref',
  13. columnType: 'mediumblob' // <-- for MySQL. Use `bytea` for PostgreSQL.
  14. }
  15. }
  16. };
  17. ```
  18.  
  19. ### In `sails console`...
  20.  
  21. ```
  22. sails> var image = fs.readFileSync('/path/to/image.png');
  23. sails> User.create({name: 'joe', avatar: image}).exec(console.log);
  24. ```
  25.  
  26. ### To retrieve
  27.  
  28. ```
  29. sails> User.findOne({name: 'joe'}).exec(function(err, user){ fs.writeFileSync('/new/file/path.png', user.avatar); });
  30. ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement