浏览代码

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 8 年前
父节点
当前提交
505621dc6e
共有 1 个文件被更改,包括 7 次插入5 次删除
  1. 7 5
      lib/transports/s3/remote.js

+ 7 - 5
lib/transports/s3/remote.js 查看文件

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 {