blob: fbbdbfd3ab241e88fe4f07d3cbe4217006e27c4b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
var skipper = require('skipper');
function OKImageService(options) {
if (!(this instanceof OKImageService)) return new OKImageService(options);
options = options || {};
if (!options.express)
throw new Error('Express not provided to OKImageService');
if (!options.s3)
throw new Error('S3 configuration not provided to OKImageService');
var express = options.express;
var router = express.Router();
router.use(skipper());
router.post('/', function(req, res) {
// req should have a method `file` on it which is
// provided by skipper. Use that to do AWS stuff
req.file('image').upload({
adapter: require('skipper-s3'),
key: options.s3.key,
secret: options.s3.secret,
bucket: options.s3.bucket,
dirname: options.s3.dirname,
maxBytes: options.s3.maxbytes,
headers: {
'x-amz-acl': 'public-read'
}
}, function (err, uploadedFiles) {
res.json(uploadedFiles);
});
});
this._middleware = router;
}
OKImageService.prototype.middleware = function() {
return this._middleware;
};
module.exports = {
OKImageService: OKImageService
};
|