2017-04-09 105 views
0

我正在嘗試使用此模塊https://www.npmjs.com/package/s3-uploader,但對於我來說目前還不清楚如何實現它。如何爲我的路由器做一個POST帶有NodeJS和s3-uploader模塊的AWS S3圖像上傳器

.post('/upload', ensureAuthenticated, (req, res, next) => { 

let files = req.files; 

let client = new Upload(process.env.AWS_BUCKET_NAME, { 
    aws: { 
    path: process.env.AWS_BUCKET_PATH, 
    region: process.env.AWS_BUCKET_REGION, 
    acl: 'public-read' 
    }, 

    cleanup: { 
    versions: true, 
    original: false 
    }, 

    original: { 
    awsImageAcl: 'private' 
    }, 

    versions: [{ 
    maxHeight: 1040, 
    maxWidth: 1040, 
    format: 'jpg', 
    suffix: '-large', 
    quality: 80, 
    awsImageExpires: 31536000, 
    awsImageMaxAge: 31536000 
    },{ 
    maxWidth: 780, 
    aspect: '3:2!h', 
    suffix: '-medium' 
    },{ 
    maxWidth: 320, 
    aspect: '16:9!h', 
    suffix: '-small' 
    },{ 
    maxHeight: 100, 
    aspect: '1:1', 
    format: 'png', 
    suffix: '-thumb1' 
    },{ 
    maxHeight: 250, 
    maxWidth: 250, 
    aspect: '1:1', 
    suffix: '-thumb2' 
    }] 
}); 

client.upload(files.file.path, {}, function(err, versions, meta) { 
    if (err) { throw err; } 

    versions.forEach(function(image) { 
    console.log(image.width, image.height, image.url); 
    // 1024 760 https://my-bucket.s3.amazonaws.com/path/110ec58a-a0f2-4ac4-8393-c866d813b8d1.jpg 
    }); 
}); 
} 

.post裏面我複製並粘貼到網站NPM他們的代碼,並改變了變量的值,以我的價值觀。

我收到此錯誤:

Error: Command failed: identify -format "name= 
size=%[size] 
format=%m 
colorspace=%[colorspace] 
height=%[height] 
width=%[width] 
orientation=%[orientation] 
" /images/logo.png 
/bin/sh: identify: command not found 

    at ChildProcess.exithandler (child_process.js:206:12) 
    at emitTwo (events.js:106:13) 
    at ChildProcess.emit (events.js:191:7) 
    at maybeClose (internal/child_process.js:877:16) 
    at Socket.<anonymous> (internal/child_process.js:334:11) 
    at emitOne (events.js:96:13) 
    at Socket.emit (events.js:188:7) 
    at Pipe._handle.close [as _onclose] (net.js:498:12) 

我發現在這個線程相關但不完全有益的話題: Node.js S3-uploader issue

回答

0

這裏是解決方案:

唯一我所做的是在我的本地主機上安裝imagemagick。

你必須在你的終端上運行這個。

cd $HOME

brew install imagemagick

當完成,你可以運行此看到的版本和細節

brew info imagemagick

如果你沒有brew,那麼你需要安裝它。

謝謝