feat(s3): support setting for force using path style endpoint (#1559)
This commit is contained in:
parent
6ceb255512
commit
4e8ab75211
2 changed files with 11 additions and 8 deletions
|
@ -65,6 +65,9 @@ type PolicyOption struct {
|
||||||
TPSLimit float64 `json:"tps_limit,omitempty"`
|
TPSLimit float64 `json:"tps_limit,omitempty"`
|
||||||
// 每秒 API 请求爆发上限
|
// 每秒 API 请求爆发上限
|
||||||
TPSLimitBurst int `json:"tps_limit_burst,omitempty"`
|
TPSLimitBurst int `json:"tps_limit_burst,omitempty"`
|
||||||
|
// Set this to `true` to force the request to use path-style addressing,
|
||||||
|
// i.e., `http://s3.amazonaws.com/BUCKET/KEY `
|
||||||
|
S3ForcePathStyle bool `json:"s3_path_style"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// thumbSuffix 支持缩略图处理的文件扩展名
|
// thumbSuffix 支持缩略图处理的文件扩展名
|
||||||
|
@ -122,7 +125,7 @@ func (policy *Policy) BeforeSave() (err error) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
//SerializeOptions 将序列后的Option写入到数据库字段
|
// SerializeOptions 将序列后的Option写入到数据库字段
|
||||||
func (policy *Policy) SerializeOptions() (err error) {
|
func (policy *Policy) SerializeOptions() (err error) {
|
||||||
optionsValue, err := json.Marshal(&policy.OptionsSerialized)
|
optionsValue, err := json.Marshal(&policy.OptionsSerialized)
|
||||||
policy.Options = string(optionsValue)
|
policy.Options = string(optionsValue)
|
||||||
|
|
|
@ -41,7 +41,7 @@ type UploadPolicy struct {
|
||||||
Conditions []interface{} `json:"conditions"`
|
Conditions []interface{} `json:"conditions"`
|
||||||
}
|
}
|
||||||
|
|
||||||
//MetaData 文件信息
|
// MetaData 文件信息
|
||||||
type MetaData struct {
|
type MetaData struct {
|
||||||
Size uint64
|
Size uint64
|
||||||
Etag string
|
Etag string
|
||||||
|
@ -71,7 +71,7 @@ func (handler *Driver) InitS3Client() error {
|
||||||
Credentials: credentials.NewStaticCredentials(handler.Policy.AccessKey, handler.Policy.SecretKey, ""),
|
Credentials: credentials.NewStaticCredentials(handler.Policy.AccessKey, handler.Policy.SecretKey, ""),
|
||||||
Endpoint: &handler.Policy.Server,
|
Endpoint: &handler.Policy.Server,
|
||||||
Region: &handler.Policy.OptionsSerialized.Region,
|
Region: &handler.Policy.OptionsSerialized.Region,
|
||||||
S3ForcePathStyle: aws.Bool(true),
|
S3ForcePathStyle: &handler.Policy.OptionsSerialized.S3ForcePathStyle,
|
||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -289,17 +289,17 @@ func (handler *Driver) Source(
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
contentDescription := aws.String("attachment; filename=\"" + url.PathEscape(fileName) + "\"")
|
||||||
|
if !isDownload {
|
||||||
|
contentDescription = nil
|
||||||
|
}
|
||||||
req, _ := handler.svc.GetObjectRequest(
|
req, _ := handler.svc.GetObjectRequest(
|
||||||
&s3.GetObjectInput{
|
&s3.GetObjectInput{
|
||||||
Bucket: &handler.Policy.BucketName,
|
Bucket: &handler.Policy.BucketName,
|
||||||
Key: &path,
|
Key: &path,
|
||||||
ResponseContentDisposition: aws.String("attachment; filename=\"" + url.PathEscape(fileName) + "\""),
|
ResponseContentDisposition: contentDescription,
|
||||||
})
|
})
|
||||||
|
|
||||||
if ttl == 0 {
|
|
||||||
ttl = 3600
|
|
||||||
}
|
|
||||||
|
|
||||||
signedURL, err := req.Presign(time.Duration(ttl) * time.Second)
|
signedURL, err := req.Presign(time.Duration(ttl) * time.Second)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
|
|
Loading…
Add table
Reference in a new issue