diff --git a/README.md b/README.md
index 957757c..0ad244b 100644
--- a/README.md
+++ b/README.md
@@ -60,7 +60,7 @@ The following storage backends are available:
|Name|Options|Notes
|----|-------|-----
|LocalFS|```-filespath files/``` -- Path to store uploads (default is files/)
```-metapath meta/``` -- Path to store information about uploads (default is meta/)|Enabled by default, this backend uses the filesystem|
-|S3|```-s3-endpoint https://...``` -- S3 endpoint
```-s3-region us-east-1``` -- S3 region
```-s3-bucket mybucket``` -- S3 bucket to use for files and metadata
Environment variables to provide:
```AWS_ACCESS_KEY_ID``` -- the S3 access key
```AWS_SECRET_ACCESS_KEY ``` -- the S3 secret key
```AWS_SESSION_TOKEN``` (optional) -- the S3 session token|Use with any S3-compatible provider.
This implementation will stream files through the linx instance (every download will request and stream the file from the S3 bucket).
For high-traffic environments, one might consider using an external caching layer such as described [in this article](https://blog.sentry.io/2017/03/01/dodging-s3-downtime-with-nginx-and-haproxy.html).|
+|S3|```-s3-endpoint https://...``` -- S3 endpoint
```-s3-region us-east-1``` -- S3 region
```-s3-bucket mybucket``` -- S3 bucket to use for files and metadata
```-s3-use-path-style``` -- force path-style addresing (e.g. https://s3.amazonaws.com/linx/example.txt)
Environment variables to provide:
```AWS_ACCESS_KEY_ID``` -- the S3 access key
```AWS_SECRET_ACCESS_KEY ``` -- the S3 secret key
```AWS_SESSION_TOKEN``` (optional) -- the S3 session token|Use with any S3-compatible provider.
This implementation will stream files through the linx instance (every download will request and stream the file from the S3 bucket).
For high-traffic environments, one might consider using an external caching layer such as described [in this article](https://blog.sentry.io/2017/03/01/dodging-s3-downtime-with-nginx-and-haproxy.html).|
#### SSL with built-in server
diff --git a/backends/s3/s3.go b/backends/s3/s3.go
index 7ae326c..45067c1 100644
--- a/backends/s3/s3.go
+++ b/backends/s3/s3.go
@@ -177,7 +177,7 @@ func (b S3Backend) List() ([]string, error) {
return output, nil
}
-func NewS3Backend(bucket string, region string, endpoint string) S3Backend {
+func NewS3Backend(bucket string, region string, endpoint string, forcePathStyle bool) S3Backend {
awsConfig := &aws.Config{}
if region != "" {
awsConfig.Region = aws.String(region)
@@ -185,6 +185,9 @@ func NewS3Backend(bucket string, region string, endpoint string) S3Backend {
if endpoint != "" {
awsConfig.Endpoint = aws.String(endpoint)
}
+ if forcePathStyle == true {
+ awsConfig.S3ForcePathStyle = aws.Bool(true)
+ }
sess := session.Must(session.NewSession(awsConfig))
svc := s3.New(sess)
diff --git a/server.go b/server.go
index 851a7cf..7883a07 100644
--- a/server.go
+++ b/server.go
@@ -64,6 +64,7 @@ var Config struct {
s3Endpoint string
s3Region string
s3Bucket string
+ s3ForcePathStyle bool
}
var Templates = make(map[string]*pongo2.Template)
@@ -138,7 +139,7 @@ func setup() *web.Mux {
}
if Config.s3Bucket != "" {
- storageBackend = s3.NewS3Backend(Config.s3Bucket, Config.s3Region, Config.s3Endpoint)
+ storageBackend = s3.NewS3Backend(Config.s3Bucket, Config.s3Region, Config.s3Endpoint, Config.s3ForcePathStyle)
} else {
storageBackend = localfs.NewLocalfsBackend(Config.metaDir, Config.filesDir)
}
@@ -265,6 +266,8 @@ func main() {
"S3 region")
flag.StringVar(&Config.s3Bucket, "s3-bucket", "",
"S3 bucket to use for files and metadata")
+ flag.BoolVar(&Config.s3ForcePathStyle, "s3-force-path-style", false,
+ "Force path-style addressing for S3 (e.g. https://s3.amazonaws.com/linx/example.txt)")
iniflags.Parse()