MCPcopy Index your code
hub / github.com/apache/answer / uploadImageFile

Method uploadImageFile

internal/service/uploader/upload.go:308–341  ·  view source on GitHub ↗
(ctx *gin.Context, file *multipart.FileHeader, fileSubPath string)

Source from the content-addressed store, hash-verified

306}
307
308func (us *uploaderService) uploadImageFile(ctx *gin.Context, file *multipart.FileHeader, fileSubPath string) (
309 url string, err error) {
310 siteGeneral, err := us.siteInfoService.GetSiteGeneral(ctx)
311 if err != nil {
312 return "", err
313 }
314 siteAdvanced, err := us.siteInfoService.GetSiteAdvanced(ctx)
315 if err != nil {
316 return "", err
317 }
318 filePath := path.Join(us.serviceConfig.UploadPath, fileSubPath)
319 if err := ctx.SaveUploadedFile(file, filePath); err != nil {
320 return "", errors.InternalServer(reason.UnknownError).WithError(err).WithStack()
321 }
322
323 src, err := file.Open()
324 if err != nil {
325 return "", errors.InternalServer(reason.UnknownError).WithError(err).WithStack()
326 }
327 defer func() {
328 _ = src.Close()
329 }()
330
331 if !checker.DecodeAndCheckImageFile(filePath, siteAdvanced.GetMaxImageMegapixel()) {
332 return "", errors.BadRequest(reason.UploadFileUnsupportedFileFormat)
333 }
334
335 if err := removeExif(filePath); err != nil {
336 log.Error(err)
337 }
338
339 url = fmt.Sprintf("%s/uploads/%s", siteGeneral.SiteUrl, fileSubPath)
340 return url, nil
341}
342
343func (us *uploaderService) uploadAttachmentFile(ctx *gin.Context, file *multipart.FileHeader, originalFilename, fileSubPath string) (
344 downloadUrl string, err error) {

Callers 3

UploadAvatarFileMethod · 0.95
UploadPostFileMethod · 0.95
UploadBrandingFileMethod · 0.95

Calls 7

DecodeAndCheckImageFileFunction · 0.92
removeExifFunction · 0.85
GetMaxImageMegapixelMethod · 0.80
GetSiteGeneralMethod · 0.65
GetSiteAdvancedMethod · 0.65
CloseMethod · 0.65
OpenMethod · 0.45

Tested by

no test coverage detected