|
@@ -154,23 +154,37 @@ func (mu *MegaUploader) upload(w http.ResponseWriter, r *http.Request) {
|
|
|
if share.SizeLimit.Bytes() > 0 {
|
|
|
sizelimit = share.SizeLimit.Bytes()
|
|
|
}
|
|
|
- err = r.ParseMultipartForm(int64(sizelimit))
|
|
|
+ mpreader, err := r.MultipartReader()
|
|
|
if err != nil {
|
|
|
fmt.Fprintln(os.Stderr, err)
|
|
|
http.Error(w, "Bad request: error parsing form", http.StatusBadRequest)
|
|
|
return
|
|
|
}
|
|
|
- file, header, err := r.FormFile("file")
|
|
|
+ part, err := mpreader.NextPart()
|
|
|
if err != nil {
|
|
|
- http.Error(w, "No file uploaded", http.StatusBadRequest)
|
|
|
+ fmt.Fprintln(os.Stderr, err)
|
|
|
+ http.Error(w, "Bad request: error reading part from multipart form", http.StatusBadRequest)
|
|
|
+ }
|
|
|
+ fname, err := share.Upload(part, filepath.Base(part.FileName()))
|
|
|
+ if err != nil {
|
|
|
+ fmt.Fprintln(os.Stderr, err)
|
|
|
+ http.Error(w, "Error uploading", http.StatusInternalServerError)
|
|
|
return
|
|
|
}
|
|
|
- fname, err := share.Upload(file, filepath.Base(header.Filename))
|
|
|
+ finfo, err := os.Stat(fname)
|
|
|
if err != nil {
|
|
|
fmt.Fprintln(os.Stderr, err)
|
|
|
http.Error(w, "Error uploading", http.StatusInternalServerError)
|
|
|
return
|
|
|
}
|
|
|
+ if uint64(finfo.Size()) > sizelimit {
|
|
|
+ err = os.Remove(fname)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Fprintln(os.Stderr, "could not delete file exceeding size limit", err)
|
|
|
+ }
|
|
|
+ http.Error(w, "File size limit exceeded", http.StatusBadRequest)
|
|
|
+ return
|
|
|
+ }
|
|
|
fname = filepath.Base(fname)
|
|
|
u, err := mu.Conf.GetShareURL(sharename)
|
|
|
if err != nil {
|