0

Below is my app.js file.. Whenever i make an attempt to resize and upload my image using multer-imager module a zero byte file is getting created everytime and i am not getting any response (keeps loading on post action).

/*********app.js*********/


var express = require('express'),
    aws = require('aws-sdk'),
    bodyParser = require('body-parser'),
    multer = require('multer'),
    imager = require('multer-imager'),
    multerS3 = require('multer-s3');
    gm = require('gm');
var Upload = require('s3-uploader');



var app = express(),
    s3 = new aws.S3();

app.use(bodyParser.json());


var upload = multer({
  storage: imager({
    dirname: 'directory',
    bucket: 'bucket',
    accessKeyId: 'accessKeyId',
    secretAccessKey: 'my secretAccessKey',
    region: 'my region',
    filename: function (req, file, cb) {  // [Optional]: define filename (default: random)
      cb(null, Date.now())                // i.e. with a timestamp
    },                                    //
    gm: {                                 // [Optional]: define graphicsmagick options
      width: 200,                         // doc: http://aheckmann.github.io/gm/docs.html#resize
      height: 200,
      options: '!',
      format: 'png'                       // Default: jpg
    },
    s3 : {                                // [Optional]: define s3 options
      Metadata: {                         // http://docs.aws.amazon.com/AmazonS3/latest/API/RESTObjectPUT.html
        'customkey': 'data'               // "x-amz-meta-customkey","value":"data"
      }
    }
  })
});

 app.post('/upload', upload.any(), function(req, res, next){ 
 console.log(req.files); // Print upload details
 res.send('Successfully uploaded!');
 }); 


app.get('/', function (req, res) {
    res.sendFile(__dirname + '/index.html');
});



app.listen(3001, function () {
    console.log('Example app listening on port 3001!');
});

The below is my index.html file.

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
Hey! Lets try uploading to s3 directly :)

<form method="post" enctype="multipart/form-data" action="/upload">
    <p>
        <input type="text" name="title" placeholder="optional title"/>
    </p>

    <p>
        <input type="file" name="upl"/>
        <!-- <input type="file" name="uplo"/> -->
    </p>

    <p>
        <input type="submit"/>
    </p>
</form>
</body>
</html>

but i can able up upload an image without doing anykind of modification using multer-s3 module.But resizing is mandatory for me.Help me to get rectify these error.

Jagadeesh
  • 1,967
  • 8
  • 24
  • 47

1 Answers1

1

I think GraphicsMagick package not installed in your system(Not NPM package).

Please go through GraphicsMagick guide and install GraphicsMagick in your system

http://www.graphicsmagick.org/README.html

Jijo Paulose
  • 1,896
  • 18
  • 20
  • its working fine .. I have installed GraphicsMagick using the below link http://linuxg.net/how-to-install-graphicsmagick-1-3-18-on-ubuntu-13-10-13-04-12-10-12-04-linux-mint-16-15-14-13-pear-os-8-7-and-elementary-os-0-2/ But how to make my images as default public? usually i will do this by giving acl= public-read.but it doesnt get suite here.. – Jagadeesh Jul 31 '17 at 06:16
  • s3.upload({ Bucket:, Key: , Body: , ACL: 'public-read' },function (resp) {}) – Jijo Paulose Jul 31 '17 at 06:23
  • http://docs.aws.amazon.com/AmazonS3/latest/dev/ACLOverview.html#CannedACL – Jijo Paulose Jul 31 '17 at 06:23
  • can you show me with my code?where i have to make a change? – Jagadeesh Jul 31 '17 at 06:25