S3: add public_url, fix Content-Disposition, add oss-file proxy

This commit is contained in:
Lizandro Guarnizo
2026-06-10 09:34:17 -05:00
parent 0fc7b8b94d
commit cf078a6e5f
4 changed files with 165 additions and 2 deletions
+1
View File
@@ -17,6 +17,7 @@ type OssApi struct {
BucketName string `gorm:"not null" json:"bucket_name"` // Nombre del bucket o access point
Region string `gorm:"size:50" json:"region"` // Región, opcional
IsActive bool `gorm:"default:true" json:"is_active"` // Activar o desactivar config
PublicURL string `gorm:"size:255" json:"public_url"` // URL pública para S3 (opcional)
Notes string `gorm:"type:text" json:"notes"`
}
+15 -2
View File
@@ -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
}