2017-07-31 26 views
0

下面是我的app.js文件..每當我試圖調整大小和上傳我的圖片使用多個成像模塊零字節文件獲取創建每次,我沒有得到任何響應(不斷加載後發表的動作)。在s3中創建零字節文件,同時嘗試在nodejs中使用multer調整大小和上傳?

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

以下是我的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> 

但我可以能夠了上傳圖片,而無需使用multer-S3 module.But調整大小做anykind修改的是強制性的me.Help我得到糾正這些錯誤。

回答

1

我想GraphicsMagick軟件包沒有安裝在你的系統中(不是NPM軟件包)。

請通過GraphicsMagick工具指導,在你的系統

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

+0

使用下面的鏈接其工作細..我已經安裝了GraphicsMagick工具 http://linuxg.net/how-to-install安裝GraphicsMagick工具-graphicsmagick-1-3-18-ON-Ubuntu的13-10-13-04-12-10-12-04-Linux的薄荷16-15-14-13梨-OS-8-7和-elementary-os-0-2/ 但是,如何使我的圖像作爲默認公開? , 身體: 通常我會通過給 ACL =公共read.but它沒有在這裏得到一套.. – Jagadeesh

+0

s3.upload({ 鬥:, 重點做到這一點, ACL: '公共 - 讀' },function(resp){}) –

+0

http://docs.aws.amazon.com/AmazonS3/latest/dev/ACLOverview.html#CannedACL –

相關問題