// SaveImageRepresentations saves files to disk func (m *Image) SaveImageRepresentations(f multipart.File) error { // If we have no path, set it to a default value /files/images/id/name if len(m.Path) == 0 { err := m.SetDefaultOriginalPath() if err != nil { return err } } // Write out several representations of this file to disk options := []file.Options{ file.Options{path.Join("public", m.Path), 4000, 4000, 100}, file.Options{path.Join("public", m.LargePath()), 2000, 2000, 70}, file.Options{path.Join("public", m.SmallPath()), 400, 400, 60}, file.Options{path.Join("public", m.IconPath()), 200, 200, 60}, } // Make sure our path exists first err := file.CreatePathTo(path.Join("public", m.Path)) if err != nil { return err } return file.SaveJpegRepresentations(f, options) }
// SaveFile saves files to disk func (m *File) saveFile(fh *multipart.FileHeader) error { // Retreive the form image data by opening the referenced tmp file. f, err := fh.Open() if err != nil { return err } // If we have no path, set it to a default value /files/documents/id/name if len(m.Path) == 0 { err = m.NewFilePath(fh) if err != nil { return err } } // Make sure our path exists first err = file.CreatePathTo(m.Path) if err != nil { return err } // Write out our file to disk return file.Save(f, m.Path) }