fix(storage) handle download filename

This commit is contained in:
neo-f 2023-03-23 22:54:18 +08:00
parent 50713cdbd8
commit b23b3ee550
2 changed files with 7 additions and 4 deletions

View File

@ -73,7 +73,7 @@ func (df *DocFolderWithChildren) ToTreeSchema() *schema.DocFolderWithChildren {
type Doc struct {
Base
Name string `gorm:"column:name;type:varchar;not null"` // 文件名称
Name string `gorm:"column:name;type:varchar;not null"` // 文件名称
IsDeletable bool `gorm:"column:is_deletable;type:boolean;not null;default:true"` // 是否允许被删除
IsEditable bool `gorm:"column:is_editable;type:boolean;not null;default:true"` // 是否允许编辑名称
FolderID string `gorm:"column:folder_id;type:varchar;index:idx_folder_id"` // 文件夹ID
@ -98,7 +98,7 @@ func (d *Doc) ToSchema(ctx context.Context) *schema.Doc {
}
func (d *Doc) PresignedURL(ctx context.Context) (*url.URL, error) {
return dal.GetStorage().PresignedGetObject(ctx, d.ObjectName, time.Hour)
return dal.GetStorage().PresignedGetObject(ctx, d.ObjectName, time.Hour, d.Name)
}
func (*Doc) TableName() string {

View File

@ -45,8 +45,11 @@ func (m *Storage) PresignedPutObject(ctx context.Context, objectName string, exp
}
// PresignedGetObject implements ObjectStorage
func (m *Storage) PresignedGetObject(ctx context.Context, objectName string, expires time.Duration) (u *url.URL, err error) {
return m.client.PresignedGetObject(ctx, m.bucket, objectName, expires, nil)
func (m *Storage) PresignedGetObject(ctx context.Context, objectName string, expires time.Duration, fileName string) (u *url.URL, err error) {
p := url.Values{
"response-content-disposition": []string{"attachment; filename*=utf-8''" + url.QueryEscape("真的吗.txt")},
}
return m.client.PresignedGetObject(ctx, m.bucket, objectName, expires, p)
}
// MoveObject implements ObjectStorage