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我得到纠正这些错误。
使用下面的链接其工作细..我已经安装了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
s3.upload({ 斗:, 重点做到这一点, ACL: '公共 - 读' },function(resp){}) –
http://docs.aws.amazon.com/AmazonS3/latest/dev/ACLOverview.html#CannedACL –