2017-07-31 4 views
0

以下は私のapp.jsファイルです。いつでも、multer-imagerモジュールを使ってイメージのサイズを変更してアップロードしようとすると、ゼロバイトのファイルが毎回作成されていて、レスポンスが得られません。nodejsでmulterを使用してサイズを変更してアップロードしようとしているときに、s3にゼロバイトファイルが作成されていますか?

/*********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を使用して変更のanykindを行うことなく画像をアップロードすることができますmodule.Butサイズ変更が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-mint-16-15-14-13-pear-os-8-7-and -elementary-os-0-2/ しかし、私の画像をデフォルト公開するには? 通常、私はそれが... – Jagadeesh

+0

s3.upload({ バケツ:,キー ここでスイートを取得doesntの ACL =公開read.butを与えることによってこれを行います:、 本体:、 ACL: '公開読み' }、function(resp){}) –

+0

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

関連する問題