S3: add public_url, fix Content-Disposition, add oss-file proxy
This commit is contained in:
@@ -163,6 +163,7 @@ type s3OSS struct {
|
||||
client *minio.Client
|
||||
bucketName string
|
||||
endpoint string
|
||||
publicURL string
|
||||
}
|
||||
|
||||
func newS3OSS(cfg *models.OssApi) (OSSProvider, error) {
|
||||
@@ -190,18 +191,26 @@ func newS3OSS(cfg *models.OssApi) (OSSProvider, error) {
|
||||
client: client,
|
||||
bucketName: cfg.BucketName,
|
||||
endpoint: cfg.Endpoint,
|
||||
publicURL: cfg.PublicURL,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *s3OSS) BucketName() string { return s.bucketName }
|
||||
func (s *s3OSS) Endpoint() string { return s.endpoint }
|
||||
func (s *s3OSS) PublicURL(objectKey string) string {
|
||||
if s.publicURL != "" {
|
||||
return fmt.Sprintf("%s/%s/%s", s.publicURL, s.bucketName, objectKey)
|
||||
}
|
||||
return fmt.Sprintf("%s/%s/%s", s.endpoint, s.bucketName, objectKey)
|
||||
}
|
||||
|
||||
func (s *s3OSS) UploadFile(objectKey, filePath string) error {
|
||||
ctx := context.Background()
|
||||
_, err := s.client.FPutObject(ctx, s.bucketName, objectKey, filePath, minio.PutObjectOptions{})
|
||||
_, err := s.client.FPutObject(ctx, s.bucketName, objectKey, filePath, minio.PutObjectOptions{
|
||||
UserMetadata: map[string]string{
|
||||
"Content-Disposition": "attachment",
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("error subiendo archivo a S3: %w", err)
|
||||
}
|
||||
@@ -275,7 +284,11 @@ func (s *s3OSS) SignedURL(objectKey string, expireSeconds int) (string, error) {
|
||||
|
||||
func (s *s3OSS) UploadFromReader(objectKey, contentType string, r io.Reader) error {
|
||||
ctx := context.Background()
|
||||
opts := minio.PutObjectOptions{}
|
||||
opts := minio.PutObjectOptions{
|
||||
UserMetadata: map[string]string{
|
||||
"Content-Disposition": "attachment",
|
||||
},
|
||||
}
|
||||
if contentType != "" {
|
||||
opts.ContentType = contentType
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user