Example #1
0
func (fs *Files) Upload(conf *config.Config, stor *storage.Storage, r *http.Request, w http.ResponseWriter) (err error) {
	// make temp files object
	tmpfs := &TmpFiles{r: r, fields: make(map[string]*temp.File), result: make(map[string]*temp.File), tmpDir: conf.TmpDir}
	defer tmpfs.Close()

	// upload
	for _, f := range *fs {
		err = f.Upload(tmpfs)
		if err != nil {
			return
		}
	}

	result := tmpfs.Result()

	// add to storage and set stae
	for name, tf := range result {
		aelog.Debugf("Uploader add file: %s (%s, %s)", name, utils.HumanBytes(tf.Size), tf.MimeType)
		file, _ := stor.Add(name, tf.File, tf.Size)
		for _, f := range *fs {
			if f.Name == name {
				f.SetState(file)
			}
		}
	}

	return
}
Example #2
0
func (u unZip) saveFile(to string, zf *zip.File, s *storage.Storage) (fs int64, err error) {
	if zf.FileInfo().Size() == 0 {
		return
	}
	fname := strings.Trim(to, "/") + "/" + strings.Trim(zf.Name, "/")
	reader, err := zf.Open()
	if err != nil {
		return
	}
	defer reader.Close()
	if f, err := s.Add(fname, reader, zf.FileInfo().Size()); err == nil {
		return f.FSize, nil
	}
	return
}