0
/********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');



var app = express(),


app.use(bodyParser.json());


var upload = multer({
 storage: imager({
    dirname: 'avatar',
    bucket: 'my bucket',
    accessKeyId: 'myaccesskey',
    secretAccessKey: 'secretaccesskey',
    region: 'Asia Pacific (Mumbai)',
    signatureVersion: 'v4',
    filename: function (req, file, cb) {  
              cb(null, Date.now())                
     },                                    
     gm: {                                  
      width: 200,                         
      height: 200,
      options: '!',
      format: 'png'                       
     },
    s3 : {                                
    Metadata: {                        
    'acl': 'public-read'              
   }
  }

})
});


 app.post('/upload', upload.array('upl', 1), 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!');
});

Below is my index.html file....

 /***************index.html*********************/
    <!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>
    /**********************************************/

When i tried to upload and resize my image using the above code i am getting the following error.But when i tried to upload my file directly by not resizing it went successful with the help of npm multer-s3 module but i couldnt do resizing or reduce the size of my thumbnails. using multer s3 module.i need to reduce my thumbnail size what can be done?

error:

UnknownEndpoint: Inaccessible host: `s3.asia'. This service may not be available in the `Asia Pacific (Mumbai)' region.
    at Request.ENOTFOUND_ERROR (/path/to/folder//node_modules/s3fs/node_modules/aws-sdk/lib/event_listeners.js:393:46)
    at Request.callListeners (/path/to/folder//node_modules/s3fs/node_modules/aws-sdk/lib/sequential_executor.js:105:20)
    at Request.emit (/path/to/folder//node_modules/s3fs/node_modules/aws-sdk/lib/sequential_executor.js:77:10)
    at Request.emit (/path/to/folder//node_modules/s3fs/node_modules/aws-sdk/lib/request.js:668:14)
    at ClientRequest.error (/path/to/folder//node_modules/s3fs/node_modules/aws-sdk/lib/event_listeners.js:232:22)
    at ClientRequest.<anonymous> (/path/to/folder//node_modules/s3fs/node_modules/aws-sdk/lib/http/node.js:62:19)
    at emitOne (events.js:115:13)
    at ClientRequest.emit (events.js:210:7)
    at TLSSocket.socketErrorListener (_http_client.js:399:9)
    at emitOne (events.js:115:13)
    at TLSSocket.emit (events.js:210:7)
    at emitErrorNT (internal/streams/destroy.js:62:8)
    at _combinedTickCallback (internal/process/next_tick.js:102:11)
    at process._tickDomainCallback (internal/process/next_tick.js:198:9)

How to fix this? Is there any way to make my region avail this function?

Jagadeesh
  • 1,967
  • 8
  • 24
  • 47

1 Answers1

1

Have you tried adding the region in another format? My S3 configs look like this:

S3_REGION=eu-central-1
S3_DOMAIN=https://s3.eu-central-1.amazonaws.com/

(I'm using the aws-sdk module)

MRonline
  • 203
  • 1
  • 8