Guest User

Untitled

a guest
Feb 20th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.31 KB | None | 0 0
  1. { Error: Error in file: ./uploads/ecqrwxgz6lw.jpg
  2.  
  3. write EOF
  4. at _errnoException (util.js:1024:11)
  5. at WriteWrap.afterWrite [as oncomplete] (net.js:867:14)
  6. code: 'EOF',
  7. errno: 'EOF',
  8. syscall: 'write',
  9. killed: false,
  10. stdout: <Buffer ff d8 ff e0 00 10 4a 46 49 46 00 01 01 00 00 01 00 01 00 00 ff e1 ff fe 45 78 69 66 00 00 49 49 2a 00 08 00 00 00 0d 00 0f 01 02 00 12 00 00 00 ac 00 ... >,
  11. stderr: <Buffer >,
  12. failed: true,
  13. signal: null,
  14. cmd: 'D:\Projects\web-development\Node.js\Business\node_modules\mozjpeg\vendor\cjpeg.exe -quality 60',
  15. timedOut: false }
  16.  
  17. var multer = require('multer');
  18.  
  19. var storage = multer.diskStorage({
  20. destination: function (req, file, callback) {
  21.  
  22. callback(null, './uploads');
  23. },
  24. filename: function (req, file, callback) {
  25. var rand = Math.random().toString(36).substr(2, 12);
  26. req.rand = rand;
  27. ext = file.originalname.substring(file.originalname.lastIndexOf('.'), file.originalname.length);
  28. callback(null, rand+ext);
  29. }
  30. });
  31.  
  32. var upload = multer({
  33. storage: storage
  34. }).single('userPhoto');
  35.  
  36. module.exports = {
  37. upload: upload,
  38. };
  39.  
  40. app.post('/events/upload', upload, function (req, res) {
  41.  
  42. var fb_id = req.user.id;
  43. var email = req.user._json.email;
  44. var random = req.rand;
  45.  
  46. console.log(fb_id);
  47.  
  48. var query = {
  49. 'Fbid': fb_id
  50. },
  51. update = {
  52. $set: {
  53. email: email
  54. },
  55. $push: {
  56. events: {
  57. event: place,
  58. imageId: random
  59. }
  60. }
  61. },
  62. options = {
  63. upsert: true
  64. };
  65.  
  66. usersuploadImformation.findOneAndUpdate(query, update, options, function (err, data) {
  67. if (err) {
  68. console.log("Not able to update");
  69. }
  70. else{
  71. console.log("Updated");
  72. }
  73. });
  74.  
  75.  
  76. imagemin(['./uploads/'+random+'.{JPG,jpg}'], './uploads', {
  77. plugins: [
  78. imageminMozjpeg({
  79. quality: 60,
  80. progressive: true
  81.  
  82. })
  83. ]
  84. }).then(files => {
  85. console.log(files);
  86. //=> [{data: <Buffer 89 50 4e …>, path: 'build/images/foo.jpg'}, …]
  87. }).catch((err)=>{
  88. console.log(err);
  89. });
  90.  
  91.  
  92.  
  93. });
Add Comment
Please, Sign In to add comment