UploadHandler
This commit is contained in:
parent
5d746323c1
commit
e635301235
@ -2,9 +2,39 @@ package handlers
|
||||
|
||||
import "github.com/labstack/echo/v4"
|
||||
|
||||
type FileInfo struct {
|
||||
FileName string `json:"fileName"`
|
||||
FileSize int64 `json:"fileSize"`
|
||||
FileType string `json:"fileType"`
|
||||
}
|
||||
|
||||
func RootHandler(c echo.Context) error {
|
||||
return c.JSON(200, map[string]string{
|
||||
"status": "😺",
|
||||
"docs": "https://illfillthisoutlater.com",
|
||||
})
|
||||
}
|
||||
|
||||
// UploadHandler e.POST("/upload")
|
||||
func UploadHandler(c echo.Context) error {
|
||||
file, err := c.FormFile("file")
|
||||
if err != nil {
|
||||
c.Logger().Errorf("Error retrieving file from request: %v", err)
|
||||
}
|
||||
|
||||
if file == nil {
|
||||
c.Logger().Error("No file provided in the request")
|
||||
}
|
||||
|
||||
fileName := file.Filename
|
||||
fileSize := file.Size
|
||||
fileType := file.Header.Get("Content-Type")
|
||||
|
||||
c.Logger().Infof("Received file: %s, Size: %d bytes, Type: %s", fileName, fileSize, fileType)
|
||||
|
||||
return c.JSON(200, FileInfo{
|
||||
FileName: fileName,
|
||||
FileSize: fileSize,
|
||||
FileType: fileType,
|
||||
})
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user