| | |
| | | var attachmentList []*models.Attachment |
| | | for _, fileHeader := range files { |
| | | ext := strings.ToLower(path.Ext(fileHeader.Filename))[1:] |
| | | fileParams := strings.Split(fileHeader.Filename, ".") |
| | | var fileType constvar.FileType |
| | | if value, ok := constvar.FileExtMap[ext]; ok { |
| | | fileType = value |
| | |
| | | buffer := new(bytes.Buffer) |
| | | _, _ = io.Copy(buffer, file) |
| | | fileBytes := buffer.Bytes() |
| | | fileUrl, err := upload.UploadFileToSeaWeed(string(fileType), ext, fileBytes) |
| | | fileUrl, err := upload.UploadFileToSeaWeed(string(fileType), fileHeader.Filename, fileBytes) |
| | | if err != nil { |
| | | logx.Errorf("file upload err: %v", err) |
| | | util.ResponseFormat(c, code.RequestParamError, err.Error()) |
| | |
| | | attachmentList = append(attachmentList, attachment) |
| | | |
| | | if fileType == constvar.FileType_Picture { |
| | | thumbnailBytes, err := image.CreateThumbnail(fileBytes, 0, 600, 800) |
| | | thumbnailBytes, err := image.CreateThumbnail(fileBytes, 60, 0, 0) |
| | | if err != nil { |
| | | logx.Errorf("file upload err: %v", err) |
| | | util.ResponseFormat(c, code.RequestParamError, "生成缩略图失败:"+err.Error()) |
| | | return |
| | | } |
| | | thumbnailUrl, err := upload.UploadFileToSeaWeed(string(constvar.FileType_Thumbnail), ext, thumbnailBytes) |
| | | thumbnailUrl, err := upload.UploadFileToSeaWeed(string(constvar.FileType_Thumbnail), fileParams[0]+"thumbnail."+ext, thumbnailBytes) |
| | | if err != nil { |
| | | logx.Errorf("file upload err: %v", err) |
| | | util.ResponseFormat(c, code.RequestParamError, err.Error()) |