func (handler FileHandler) BeforeStore(value interface{}, existing interface{}, mode string) (interface{}, error) {
	filePath := value.(string)
	if existing != nil && filePath == existing.(string) {
		return filePath, nil
	}
	if filePath == "" {
		return "", nil
	}
	temp := util.GetConfig("general", "upload_tempfolder")
	if !strings.HasPrefix(filePath, temp+"/") {
		return nil, fieldtype.NewValidationError("File needs to be under temp")
	}
	arr := strings.Split(filePath, "/")
	filename := arr[len(arr)-1]
	rand := util.RandomStr(3)
	secondLevel := string(rand)
	firstLevel := string(rand[0])
	newFolder := "file/" + firstLevel + "/" + secondLevel
	newFolderAbs := util.VarFolder() + "/" + newFolder
	_, err := os.Stat(newFolderAbs)
	if os.IsNotExist(err) {
		err = os.MkdirAll(newFolderAbs, 0775)
		if err != nil {
			return nil, err
		}
	}
	newPath := newFolder + "/" + filename
	newPathAbs := util.VarFolder() + "/" + newPath
	oldAbsPath := util.VarFolder() + "/" + filePath
	err = os.Rename(oldAbsPath, newPathAbs)
	if err != nil {
		errorMessage := "Can not move file to target " + filePath + ". error: " + err.Error()
		return nil, errors.New(errorMessage)
	}
	return newPath, nil
}
Image can be loaded from rest, or local api
package fieldtypes
import (
	"errors"
	"fmt"
	"os"
	"strings"
	"github.com/digimakergo/digimaker/core/definition"
	"github.com/digimakergo/digimaker/core/fieldtype"
	"github.com/digimakergo/digimaker/core/log"
	"github.com/digimakergo/digimaker/core/util"
)
const defaultMaxSize = 10.0
type FileParameters struct {
	Format  string  `mapstructure:"format"`    
	MaxSize float64 `mapstructure:"max_size"`  
}
type FileHandler struct {
	definition.FieldDef
	Params FileParameters
}
func (handler FileHandler) LoadInput(input interface{}, mode string) (interface{}, error) {
	filePath := fmt.Sprint(input)
	if filePath != "" {
		formatParam := handler.Params.Format
		if formatParam != "" {
			formats := util.Split(handler.Params.Format)
			validFormat := false
			for _, format := range formats {
				lowerPath := strings.ToLower(filePath)
				if strings.HasSuffix(lowerPath, format) {
					validFormat = true
				}
			}
			if !validFormat {
				return nil, fieldtype.NewValidationError(fmt.Sprintf("Format not allowed. allowed are: %v", formatParam))
			}
		}
		absPath := util.VarFolder() + "/" + filePath
		info, err := os.Stat(absPath)
		if err != nil {
			return nil, fieldtype.NewValidationError("Can't find file of " + filePath)
		}
		maxSize := defaultMaxSize
		if handler.Params.MaxSize > 0 {
			maxSize = handler.Params.MaxSize
		}
		if info.Size() > int64(maxSize*1024*1024) {
			return nil, fieldtype.NewValidationError(fmt.Sprintf("File is should be less than %vM", handler.Params.MaxSize))
		}
	}
	return filePath, nil
}