How to read multipart.Fileheader in an array struct

type MasterTemplate struct {
ID string form:"id" json:"id"
IsVoice bool form:"is_voice" json:"is_voice"
Title string form:"title" json:"title"
IsSms bool form:"is_sms" json:"is_sms"
Content []struct {
File *multipart.FileHeader form:"file" json:"file"
MsgTmplateLangId string form:"msg_template_lang_id" json:"msg_template_lang_id"
SMSContent string form:"sms_content" json:"sms_content"
MsgContentID string form:"msg_content_id" json:"msg_content_id"
FilePath string form:"file_path" json:"file_path"
} form:"content" json:"content"
UserID uuid.UUID form:"user_id" json:"user_id"
}

func (tmplController *MessageTemplateController) CreateMsgTemplateController(ctx *gin.Context) {

// var msgTemplate models.MasterTemplate
err := ctx.Request.ParseMultipartForm(10 * 1024 * 1024)
if err != nil {
	ctx.JSON(http.StatusBadRequest, gin.H{
		"error": err.Error(),
	})
	return
}
var contents []models.MasterTemplate

form := ctx.Request.MultipartForm
files := form.File["content[file]"]
// formFileds := form.Value
// formFields := ctx.Request.MultipartForm.Value

for x, file := range files {

	var msgTemplate models.MasterTemplate

	msgTemplate.Content = make([]struct {
		File             *multipart.FileHeader `form:"file" json:"file"`
		MsgTmplateLangId string                `form:"msg_template_lang_id" json:"msg_template_lang_id"`
		SMSContent       string                `form:"sms_content" json:"sms_content"`
		MsgContentID     string                `form:"msg_content_id" json:"msg_content_id"`
		FilePath         string                `form:"file_path" json:"file_path"`
	}, len(files))

	// Bind the form data to the struct

	// Set the file data for this content item
	msgTemplate.Content[x].File = file
	contents = append(contents, msgTemplate)

}

ctx.JSON(http.StatusOK, gin.H{
	"response": contents,
})

}
How do I get the file with their associated information. Attached is my postman request:

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.