feat: add s3 storage provider integration
This commit is contained in:
@@ -349,20 +349,20 @@ func (s *common) CompleteUpload(ctx context.Context, tenantID, userID int64, for
|
||||
Meta: existing.Meta,
|
||||
}
|
||||
} else {
|
||||
finalPath := filepath.Join(localPath, objectKey)
|
||||
if err := os.MkdirAll(filepath.Dir(finalPath), 0o755); err != nil {
|
||||
return nil, errorx.ErrInternalError.WithCause(err)
|
||||
contentType := strings.TrimSpace(meta.MimeType)
|
||||
if contentType == "" {
|
||||
contentType = "application/octet-stream"
|
||||
}
|
||||
if err := os.Rename(mergedPath, finalPath); err != nil {
|
||||
return nil, errorx.ErrInternalError.WithCause(err)
|
||||
if err := s.storage.PutObject(ctx, objectKey, mergedPath, contentType); err != nil {
|
||||
return nil, errorx.ErrInternalError.WithCause(err).WithMsg("上传存储失败")
|
||||
}
|
||||
asset = &models.MediaAsset{
|
||||
TenantID: tid,
|
||||
UserID: userID,
|
||||
Type: consts.MediaAssetType(meta.Type),
|
||||
Status: consts.MediaAssetStatusUploaded,
|
||||
Provider: "local",
|
||||
Bucket: "default",
|
||||
Provider: s.storage.Provider(),
|
||||
Bucket: s.storage.Bucket(),
|
||||
ObjectKey: objectKey,
|
||||
Hash: hash,
|
||||
Meta: types.NewJSONType(fields.MediaAssetMeta{
|
||||
@@ -513,12 +513,12 @@ func (s *common) Upload(
|
||||
Meta: existing.Meta,
|
||||
}
|
||||
} else {
|
||||
dstPath := filepath.Join(localPath, objectKey)
|
||||
if err := os.MkdirAll(filepath.Dir(dstPath), 0o755); err != nil {
|
||||
return nil, errorx.ErrInternalError.WithCause(err).WithMsg("failed to create storage directory")
|
||||
contentType := strings.TrimSpace(file.Header.Get("Content-Type"))
|
||||
if contentType == "" {
|
||||
contentType = "application/octet-stream"
|
||||
}
|
||||
if err := os.Rename(tmpPath, dstPath); err != nil {
|
||||
return nil, errorx.ErrInternalError.WithCause(err).WithMsg("failed to finalize file")
|
||||
if err := s.storage.PutObject(ctx, objectKey, tmpPath, contentType); err != nil {
|
||||
return nil, errorx.ErrInternalError.WithCause(err).WithMsg("上传存储失败")
|
||||
}
|
||||
os.RemoveAll(tmpDir)
|
||||
|
||||
@@ -528,8 +528,8 @@ func (s *common) Upload(
|
||||
UserID: userID,
|
||||
Type: consts.MediaAssetType(typeArg),
|
||||
Status: consts.MediaAssetStatusUploaded,
|
||||
Provider: "local",
|
||||
Bucket: "default",
|
||||
Provider: s.storage.Provider(),
|
||||
Bucket: s.storage.Bucket(),
|
||||
ObjectKey: objectKey,
|
||||
Hash: hash,
|
||||
Meta: types.NewJSONType(fields.MediaAssetMeta{
|
||||
|
||||
Reference in New Issue
Block a user