Add component to upload book cover images
This commit is contained in:
24
internal/routes/uploadbookcover.go
Normal file
24
internal/routes/uploadbookcover.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package routes
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"git.artlef.fr/PersonalLibraryManager/internal/appcontext"
|
||||
"git.artlef.fr/PersonalLibraryManager/internal/myvalidator"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func PostUploadBookCoverHandler(ac appcontext.AppContext) {
|
||||
file, err := ac.C.FormFile("file")
|
||||
if err != nil {
|
||||
myvalidator.ReturnErrorsAsJsonResponse(&ac, err)
|
||||
return
|
||||
}
|
||||
filepath := file.Filename
|
||||
err = ac.C.SaveUploadedFile(file, ac.Config.ImageFolderPath+"/"+filepath)
|
||||
if err != nil {
|
||||
myvalidator.ReturnErrorsAsJsonResponse(&ac, err)
|
||||
return
|
||||
}
|
||||
ac.C.JSON(http.StatusOK, gin.H{"filepath": "/bookcover/" + filepath})
|
||||
}
|
||||
Reference in New Issue
Block a user