@@ -21,6 +21,7 @@ type Config struct {
21
21
SecretAccessKey string
22
22
Bucket string
23
23
Location string
24
+ Prefix string
24
25
PartSize uint64
25
26
UseSSL bool
26
27
}
@@ -31,7 +32,7 @@ func NewConfig(params map[string]interface{}) (config *Config) {
31
32
config = new (Config )
32
33
config .Bucket = "plik"
33
34
config .Location = "us-east-1"
34
- config .PartSize = 32 * 1024 * 1024 // 32MB
35
+ config .PartSize = 16 * 1000 * 1000 // 16MB
35
36
utils .Assign (config , params )
36
37
return
37
38
}
@@ -53,7 +54,7 @@ func (config *Config) Validate() error {
53
54
if config .Location == "" {
54
55
return fmt .Errorf ("missing location" )
55
56
}
56
- if config .PartSize < 5 * 1024 * 1024 {
57
+ if config .PartSize < 5 * 1000 * 1000 {
57
58
return fmt .Errorf ("invalid part size" )
58
59
}
59
60
return nil
@@ -100,24 +101,31 @@ func NewBackend(config *Config) (b *Backend, err error) {
100
101
101
102
// GetFile implementation for S3 Data Backend
102
103
func (b * Backend ) GetFile (file * common.File ) (reader io.ReadCloser , err error ) {
103
- return b .client .GetObject (b .config .Bucket , file .ID , minio.GetObjectOptions {})
104
+ return b .client .GetObject (b .config .Bucket , b . getObjectName ( file .ID ) , minio.GetObjectOptions {})
104
105
}
105
106
106
107
// AddFile implementation for S3 Data Backend
107
108
func (b * Backend ) AddFile (file * common.File , fileReader io.Reader ) (backendDetails string , err error ) {
108
109
if file .Size > 0 {
109
- _ , err = b .client .PutObject (b .config .Bucket , file .ID , fileReader , file .Size , minio.PutObjectOptions {ContentType : file .Type })
110
+ _ , err = b .client .PutObject (b .config .Bucket , b . getObjectName ( file .ID ) , fileReader , file .Size , minio.PutObjectOptions {ContentType : file .Type })
110
111
} else {
111
112
// https://github.com/minio/minio-go/issues/989
112
113
// Minio defaults to 128MB chunks and has to actually allocate a buffer of this size before uploading the chunk
113
114
// This can lead to very high memory usage when uploading a lot of small files in parallel
114
- // We default to 32MB which allow to store files up to 320GB ( 10000 chunks of 32MB ), feel free to adjust this parameter to your needs.
115
- _ , err = b .client .PutObject (b .config .Bucket , file .ID , fileReader , - 1 , minio.PutObjectOptions {ContentType : file .Type , PartSize : b .config .PartSize })
115
+ // We default to 16MB which allow to store files up to 160GB ( 10000 chunks of 16MB ), feel free to adjust this parameter to your needs.
116
+ _ , err = b .client .PutObject (b .config .Bucket , b . getObjectName ( file .ID ) , fileReader , - 1 , minio.PutObjectOptions {ContentType : file .Type , PartSize : b .config .PartSize })
116
117
}
117
118
return "" , err
118
119
}
119
120
120
121
// RemoveFile implementation for S3 Data Backend
121
122
func (b * Backend ) RemoveFile (file * common.File ) (err error ) {
122
- return b .client .RemoveObject (b .config .Bucket , file .ID )
123
+ return b .client .RemoveObject (b .config .Bucket , b .getObjectName (file .ID ))
124
+ }
125
+
126
+ func (b * Backend ) getObjectName (name string ) string {
127
+ if b .config .Prefix != "" {
128
+ return fmt .Sprintf ("%s/%s" , b .config .Prefix , name )
129
+ }
130
+ return name
123
131
}
0 commit comments