Skip to content

Commit 49fbb36

Browse files
sy-recordsLinkinStars
authored andcommitted
feat(storage): support to set ACL_PUBLIC_READ ENV
1 parent bdbf9b1 commit 49fbb36

File tree

4 files changed

+28
-4
lines changed

4 files changed

+28
-4
lines changed

storage-aliyunoss/aliyunoss.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"encoding/hex"
2626
"encoding/json"
2727
"fmt"
28+
"os"
2829
"path/filepath"
2930
"strings"
3031
"time"
@@ -40,6 +41,11 @@ import (
4041
//go:embed info.yaml
4142
var Info embed.FS
4243

44+
var (
45+
// aclPublicRead is the environment variable for some special platforms such as digital ocean
46+
aclPublicRead = os.Getenv("ACL_PUBLIC_READ")
47+
)
48+
4349
type Storage struct {
4450
Config *StorageConfig
4551
}
@@ -121,7 +127,11 @@ func (s *Storage) UploadFile(ctx *plugin.GinContext, condition plugin.UploadFile
121127
ObjectKey: objectKey,
122128
Reader: open,
123129
}
124-
respBody, err := bucket.DoPutObject(request, nil)
130+
var options []oss.Option
131+
if len(aclPublicRead) > 0 {
132+
options = append(options, oss.ObjectACL(oss.ACLPublicRead))
133+
}
134+
respBody, err := bucket.DoPutObject(request, options)
125135
if err != nil {
126136
resp.OriginalError = fmt.Errorf("upload file failed: %v", err)
127137
resp.DisplayErrorMsg = plugin.MakeTranslator(i18n.ErrUploadFileFailed)

storage-aliyunoss/info.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@
1717

1818
slug_name: aliyunoss_storage
1919
type: storage
20-
version: 1.2.12
20+
version: 1.2.13
2121
author: answerdev
2222
link: https://github.com/apache/answer-plugins/tree/main/storage-aliyunoss

storage-tencentyuncos/info.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@
1717

1818
slug_name: tencentyuncos_storage
1919
type: storage
20-
version: 1.0.3
20+
version: 1.0.4
2121
author: Luffy
2222
link: https://github.com/apache/answer-plugins/tree/main/storage-tencentyuncos

storage-tencentyuncos/tencentyuncos.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"fmt"
2828
"net/http"
2929
"net/url"
30+
"os"
3031
"path/filepath"
3132
"strings"
3233
"time"
@@ -42,6 +43,11 @@ import (
4243
//go:embed info.yaml
4344
var Info embed.FS
4445

46+
var (
47+
// aclPublicRead is the environment variable for some special platforms such as digital ocean
48+
aclPublicRead = os.Getenv("ACL_PUBLIC_READ")
49+
)
50+
4551
type Storage struct {
4652
Config *StorageConfig
4753
}
@@ -122,7 +128,15 @@ func (s *Storage) UploadFile(ctx *plugin.GinContext, condition plugin.UploadFile
122128
defer openFile.Close()
123129

124130
objectKey := s.createObjectKey(file.Filename, condition.Source)
125-
_, err = client.Object.Put(ctx, objectKey, openFile, nil)
131+
var options *cos.ObjectPutOptions
132+
if len(aclPublicRead) > 0 {
133+
options = &cos.ObjectPutOptions{
134+
ACLHeaderOptions: &cos.ACLHeaderOptions{
135+
XCosACL: "public-read",
136+
},
137+
}
138+
}
139+
_, err = client.Object.Put(ctx, objectKey, openFile, options)
126140
if err != nil {
127141
resp.OriginalError = fmt.Errorf("upload file failed: %v", err)
128142
resp.DisplayErrorMsg = plugin.MakeTranslator(i18n.ErrUploadFileFailed)

0 commit comments

Comments
 (0)