Changeset 22 in code for trunk/partage.go
- Timestamp:
- Oct 19, 2021, 6:35:08 AM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/partage.go
r21 r22 42 42 } 43 43 44 45 44 func writefile(f *os.File, s io.ReadCloser, contentlength int64) error { 46 45 buffer := make([]byte, 4096) … … 107 106 t, err := template.ParseFiles(conf.templatedir + "/" + f) 108 107 if err != nil { 109 w.WriteHeader(http.StatusInternalServerError)108 http.Error(w, err, http.StatusInternalServerError) 110 109 return 111 110 } … … 120 119 /* limit upload size */ 121 120 if r.ContentLength > conf.maxsize { 122 w.WriteHeader(http.StatusRequestEntityTooLarge) 123 w.Write([]byte("File is too big")) 121 http.Error(w, "File is too big", http.StatusRequestEntityTooLarge) 124 122 } 125 123 … … 133 131 134 132 if err = writefile(f, r.Body, r.ContentLength); err != nil { 135 w.WriteHeader(http.StatusInternalServerError)133 http.Error(w, err, http.StatusInternalServerError) 136 134 defer os.Remove(tmp.Name()) 137 135 return … … 150 148 for _, h := range r.MultipartForm.File["uck"] { 151 149 if h.Size > conf.maxsize { 152 w.WriteHeader(http.StatusRequestEntityTooLarge) 153 w.Write([]byte("File is too big")) 150 http.Error(w, "File is too big", http.StatusRequestEntityTooLarge) 154 151 return 155 152 } … … 157 154 post, err := h.Open() 158 155 if err != nil { 159 w.WriteHeader(http.StatusInternalServerError)156 http.Error(w, err, http.StatusInternalServerError) 160 157 return 161 158 } … … 165 162 f, err := os.Create(tmp.Name()) 166 163 if err != nil { 167 w.WriteHeader(http.StatusInternalServerError)164 http.Error(w, err, http.StatusInternalServerError) 168 165 return 169 166 } … … 171 168 172 169 if err = writefile(f, post, h.Size); err != nil { 173 w.WriteHeader(http.StatusInternalServerError)170 http.Error(w, err, http.StatusInternalServerError) 174 171 defer os.Remove(tmp.Name()) 175 172 return
Note:
See TracChangeset
for help on using the changeset viewer.