optimize: use io.NopCloser instead types.PureReader in internal/servants/web/priv.go

pull/471/head
Michael Li 10 months ago
parent 87efc21c7b
commit af74e4ecb4
No known key found for this signature in database

@ -6,6 +6,7 @@ package web
import (
"image"
"io"
"strings"
"time"
@ -22,7 +23,6 @@ import (
"github.com/rocboss/paopao-ce/internal/model/web"
"github.com/rocboss/paopao-ce/internal/servants/base"
"github.com/rocboss/paopao-ce/internal/servants/chain"
"github.com/rocboss/paopao-ce/pkg/types"
"github.com/rocboss/paopao-ce/pkg/utils"
"github.com/rocboss/paopao-ce/pkg/xerror"
"github.com/sirupsen/logrus"
@ -145,7 +145,7 @@ func (s *privSrv) UploadAttachment(req *web.UploadAttachmentReq) (*web.UploadAtt
// NOTE: 注意这里将req.File Wrap到一个io.Reader的实例对象中是为了避免下游接口去主动调Closereq.File本身是实现了
// io.Closer接口的有的下游接口会断言传参是否实现了io.Closer接口如果实现了会主动去调我们这里因为下文中可能还要继续
// 使用req.File所以应避免下游Close否则会出现潜在的bug比如这里的场景就是传一个超大的图片(>10MB)可能就会触发bug了。
data := types.PureReader(req.File)
data := io.NopCloser(req.File)
objectUrl, err := s.oss.PutObject(ossSavePath, data, req.FileSize, req.ContentType, false)
if err != nil {
logrus.Errorf("oss.putObject err: %s", err)

Loading…
Cancel
Save