-
Notifications
You must be signed in to change notification settings - Fork 2
/
route-form.js
45 lines (37 loc) · 1.44 KB
/
route-form.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
'use strict';
var conf = require('./conf');
var Conv = require('direct-upload-s3');
class RouteForm {
constructor(AWS_ACCESS_KEY_ID,
AWS_SECRET_ACCESS_KEY){
this.awsService = 's3';
this.conv = new Conv(AWS_ACCESS_KEY_ID,
AWS_SECRET_ACCESS_KEY,
this.awsService,
conf.awsRegion);
}
run(next){
// depends of current time
var base64Policy = this.conv.getBase64Policy(conf.bucketName,
conf.acl,
conf.expiresInterval,
conf.contentTypeStart,
0,
conf.contentLengthMaxMB * 1024 * 1024);
var signature = this.conv.getSignature(base64Policy);
var formParams = this.conv.getFormParams(conf.acl,
conf.outBase + "${filename}",
signature,
base64Policy);
var form = {
action: 'https://'+ conf.bucketName +'.'+ this.awsService + '-'+ conf.awsRegion +'.amazonaws.com/',
method: 'POST',
enctype: 'multipart/form-data',
contentLengthMaxMB: conf.contentLengthMaxMB,
contentTypeStart: conf.contentTypeStart,
params: formParams
};
next(null, form);
}
}
module.exports = RouteForm;