25 lines
621 B
Go
25 lines
621 B
Go
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})
|
|
}
|