-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathuploadManager.js
56 lines (49 loc) · 1.58 KB
/
uploadManager.js
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
44
45
46
47
48
49
50
51
52
53
54
55
56
// config the uploader
var options = {
tmpDir: __dirname + '/../public/uploaded/tmp',
publicDir: __dirname + '/../public/uploaded',
uploadDir: __dirname + '/../public/uploaded/files',
uploadUrl: '/uploaded/files/',
maxPostSize: 11000000000, // 11 GB
minFileSize: 1,
maxFileSize: 10000000000, // 10 GB
acceptFileTypes: /.+/i,
// Files not matched by this regular expression force a download dialog,
// to prevent executing any scripts in the context of the service domain:
inlineFileTypes: /\.(gif|jpe?g|png)$/i,
imageTypes: /\.(gif|jpe?g|png)$/i,
imageVersions: {
maxWidth: 80,
maxHeight: 80
},
accessControl: {
allowOrigin: '*',
allowMethods: 'OPTIONS, HEAD, GET, POST, PUT, DELETE',
allowHeaders: 'Content-Type, Content-Range, Content-Disposition'
},
storage : {
type : 'local'
},
nodeStatic: {
cache: 3600 // seconds to cache served files
}
};
var uploader = require('blueimp-file-upload-expressjs')(options);
module.exports = function(router) {
router.get('/upload', function(req, res) {
uploader.get(req, res, function(err, obj) {
res.send(JSON.stringify(obj));
});
});
router.post('/upload', function(req, res) {
uploader.post(req, res, function(err, obj) {
res.send(JSON.stringify(obj));
});
});
router.delete('/uploaded/files/:name', function(req, res) {
uploader.delete(req, res, function(err, obj) {
res.send(JSON.stringify(obj));
});
});
return router;
}