Advertisement
Guest User

Untitled

a guest
May 25th, 2016
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. /*
  2. * Database used: Mysql
  3. * Author: Saumya Suhagiya
  4. * Version: 1.0
  5. */
  6. var DATABASE_NAME = 'image_db';
  7. var DB_USERNAME = 'abc';
  8. var DB_PASSWORD = 'abc@123';
  9.  
  10. var Sequelize = require('sequelize');
  11. var FS = require('fs');
  12.  
  13. var sequelize = new Sequelize(
  14. DATABASE_NAME,
  15. DB_USERNAME,
  16. DB_PASSWORD, {
  17. host:'localhost',
  18. port:3306,
  19. dialect:'mysql'
  20. });
  21.  
  22. //Connect to Database
  23. sequelize.authenticate().then(function (e) {
  24. if(e) {
  25. console.log('There is connection ERROR');
  26. } else {
  27. console.log('Connection has been established successfully');
  28. }
  29. });
  30.  
  31. sequelize.sync({
  32. force: true,
  33. logging: console.log
  34.  
  35. }).then(function () {
  36. console.log('Everything is synced');
  37. var imageData = FS.readFileSync(__dirname + '/123_icon.png'); //Give image data path
  38. Image_Store.create({
  39. image_id: 123,
  40. image_type: 'png',
  41. image: imageData,
  42. image_size: 3,
  43. image_name: 'FileName'
  44. }).then(function (image_store) {
  45. try {
  46. //Store image to some location
  47. FS.writeFileSync(__dirname + '/target.png', image_store.image);
  48. } catch (e) {
  49. console.log(e+'');
  50. }
  51. });
  52. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement