Browse Source

Allow overriding the s3 endpoint domain for use with Google Cloud Storage, updated the public URL for files to load through Fastly instead of directly from S3

Michael Strickland 7 years ago
parent
commit
505621dc6e
1 changed files with 7 additions and 5 deletions
  1. 7 5
      lib/transports/s3/remote.js

+ 7 - 5
lib/transports/s3/remote.js View File

3
 
3
 
4
 module.exports = function(bucket, storagePath) {
4
 module.exports = function(bucket, storagePath) {
5
 
5
 
6
-  var s3 = new AWS.S3({ params: { Bucket: bucket } });
6
+  var s3 = new AWS.S3({
7
+    params: { Bucket: bucket },
8
+    endpoint: process.env.S3_ENDPOINT || 's3.amazonaws.com'
9
+  });
7
 
10
 
8
   // Test credentials
11
   // Test credentials
9
   s3.headBucket({}, function(err){ if (err) { throw err; } });
12
   s3.headBucket({}, function(err){ if (err) { throw err; } });
12
 
15
 
13
     var params = {
16
     var params = {
14
       Key: storagePath + key,
17
       Key: storagePath + key,
15
-      Body: fs.createReadStream(source),
16
-      ACL: "public-read"
18
+      Body: fs.createReadStream(source)
17
     };
19
     };
18
 
20
 
19
     // gzipping results in inconsistent file size :(
21
     // gzipping results in inconsistent file size :(
20
-    s3.upload(params, cb);
22
+    s3.putObject(params, cb);
21
 
23
 
22
   }
24
   }
23
 
25
 
71
 
73
 
72
   // TODO make this more configurable
74
   // TODO make this more configurable
73
   function getURL(id) {
75
   function getURL(id) {
74
-    return "https://s3.amazonaws.com/" + bucket + "/" + storagePath + "video/" + id + ".mp4";
76
+    return "https://" + bucket + "/" + storagePath + "video/" + id + ".mp4";
75
   }
77
   }
76
 
78
 
77
   return {
79
   return {