Exemplo n.º 1
0
func (s *Server) Download(name string, w http.ResponseWriter, r *http.Request) {
	_, ok := s.stor.Get(name)
	if ok {
		// File exists
		s.Err(409, r, w)
		return
	}
	url := s.downloadUrl(r)
	tf := temp.NewFile(s.conf.TmpDir)
	aelog.Debugf("Start download from %s\n", url)
	err := tf.LoadFromUrl(url)
	defer tf.Close()
	if err != nil {
		aelog.Infof("Can't download : %s, err: %v\n", url, err)
		s.Err(500, r, w)
		return
	}
	// again check for exists
	_, ok = s.stor.Get(name)
	if ok {
		s.Err(409, r, w)
		return
	}
	s.save(name, tf.Size, tf.File, r, w)
}
Exemplo n.º 2
0
func (t *TmpFiles) GetByField(field string) (f *temp.File, err error) {
	f = t.fields[field]
	if f == nil {
		aelog.Debugf("Find file by field: %s", field)
		url := t.r.FormValue(field + "_url")
		f = temp.NewFile(t.tmpDir)
		if url != "" {
			aelog.Debugf("Url found[%s]: %s", field, url)
			f.OrigName = filepath.Base(url)
			if err = f.LoadFromUrl(url); err != nil {
				return
			}
		} else {
			mf, mh, e := t.r.FormFile(field)
			if e != nil {
				err = e
				return
			}
			if err = f.LoadFromForm(mf); err != nil {
				return
			}
			f.OrigName = mh.Filename
		}
		t.fields[field] = f
	}
	return
}