add pdf upload
This commit is contained in:
@@ -74,15 +74,25 @@ func (rc *shopItemController) NewShopItemFromForm(ctx *gin.Context) (models.Shop
|
||||
variantValues := ctx.PostFormArray("variant-value[]")
|
||||
tagIds := ctx.PostFormArray("tags[]")
|
||||
image, err := ctx.FormFile("image")
|
||||
dst := "static/img/zine.jpg"
|
||||
dstImage := "static/img/zine.jpg"
|
||||
|
||||
if err == nil {
|
||||
dst = filepath.Join("static/uploads", image.Filename)
|
||||
if err := ctx.SaveUploadedFile(image, dst); err != nil {
|
||||
dstImage = filepath.Join("static/uploads", image.Filename)
|
||||
if err := ctx.SaveUploadedFile(image, dstImage); err != nil {
|
||||
return models.ShopItem{}, fmt.Errorf("Could not save image")
|
||||
}
|
||||
}
|
||||
|
||||
dstPdf := ""
|
||||
pdf, err := ctx.FormFile("pdf")
|
||||
|
||||
if err == nil {
|
||||
dstPdf = filepath.Join("static/uploads", pdf.Filename)
|
||||
if err := ctx.SaveUploadedFile(pdf, dstPdf); err != nil {
|
||||
return models.ShopItem{}, fmt.Errorf("Could not save PDF")
|
||||
}
|
||||
}
|
||||
|
||||
if name == "" || description == "" {
|
||||
return models.ShopItem{}, fmt.Errorf("Name or description empty")
|
||||
}
|
||||
@@ -124,7 +134,8 @@ func (rc *shopItemController) NewShopItemFromForm(ctx *gin.Context) (models.Shop
|
||||
Description: description,
|
||||
Category: category,
|
||||
IsPublic: true,
|
||||
Image: dst,
|
||||
Image: dstImage,
|
||||
Pdf: dstPdf,
|
||||
Variants: variants,
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user