fix: 初验针对修改

This commit is contained in:
zxr
2026-09-09 16:42:21 +08:00
parent eb2722d8a0
commit b6ffe2fcea
40 changed files with 2179 additions and 279 deletions

View File

@@ -0,0 +1,37 @@
package aliyun
import (
"context"
"fmt"
"strings"
"time"
"git.apinb.com/ops/files/internal/storage"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss"
)
func (c *Client) PrepareUpload(ctx context.Context, request storage.UploadRequest) (storage.UploadInstruction, error) {
if strings.TrimSpace(request.ObjectKey) == "" {
return storage.UploadInstruction{}, fmt.Errorf("对象键不能为空")
}
if strings.TrimSpace(request.ContentType) == "" {
return storage.UploadInstruction{}, fmt.Errorf("内容类型不能为空")
}
result, err := c.client.Presign(ctx, &oss.PutObjectRequest{
Bucket: oss.Ptr(c.bucket),
Key: oss.Ptr(request.ObjectKey),
ContentType: oss.Ptr(request.ContentType),
ForbidOverwrite: oss.Ptr("true"),
}, oss.PresignExpires(time.Duration(c.presignTTL)*time.Second))
if err != nil {
return storage.UploadInstruction{}, fmt.Errorf("生成上传预签名: %w", err)
}
return storage.UploadInstruction{
Method: result.Method,
URL: result.URL,
Headers: result.SignedHeaders,
ExpiresAt: result.Expiration,
}, nil
}