- Timestamp:
- Oct 15, 2021, 5:23:50 PM (4 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/partage.go
r11 r12 15 15 16 16 type templatedata struct { 17 Links []string 18 Size string 17 19 Maxsize string 18 20 } … … 116 118 117 119 func uploaderPut(w http.ResponseWriter, r *http.Request) { 118 / / Max 15 Gb uploads120 /* limit upload size */ 119 121 if r.ContentLength > conf.maxsize { 120 122 w.WriteHeader(http.StatusRequestEntityTooLarge) … … 135 137 } 136 138 137 resp := conf.baseuri + conf.filectx + filepath.Base(tmp.Name()) + "\r\n"139 resp := conf.baseuri + conf.filectx + filepath.Base(tmp.Name()) 138 140 w.Write([]byte(resp)) 141 } 142 143 func uploaderPost(w http.ResponseWriter, r *http.Request) { 144 /* read 32Mb at a time */ 145 r.ParseMultipartForm(32 << 20) 146 147 links := []string{} 148 for _, h := range r.MultipartForm.File["uck"] { 149 if h.Size > conf.maxsize { 150 w.WriteHeader(http.StatusRequestEntityTooLarge) 151 w.Write([]byte("File is too big")) 152 return 153 } 154 155 post, err := h.Open() 156 if err != nil { 157 w.WriteHeader(http.StatusInternalServerError) 158 return 159 } 160 defer post.Close() 161 162 tmp, _ := ioutil.TempFile(conf.filepath, "*"+path.Ext(h.Filename)) 163 f, err := os.Create(tmp.Name()) 164 if err != nil { 165 w.WriteHeader(http.StatusInternalServerError) 166 return 167 } 168 defer f.Close() 169 170 if writefile(f, post, h.Size) < 0 { 171 w.WriteHeader(http.StatusInternalServerError) 172 return 173 } 174 175 link := conf.baseuri + conf.filectx + filepath.Base(tmp.Name()) 176 links = append(links, link) 177 } 178 179 if (r.PostFormValue("output") == "html") { 180 data := templatedata{ Links: links } 181 servetemplate(w, "/upload.html", data) 182 return 183 } else { 184 for _, link := range links { 185 w.Write([]byte(link + "\r\n")) 186 } 187 } 139 188 } 140 189 … … 161 210 func uploader(w http.ResponseWriter, r *http.Request) { 162 211 switch r.Method { 212 case "POST": 213 uploaderPost(w, r) 163 214 case "PUT": 164 215 uploaderPut(w, r) -
trunk/templates/index.html
r11 r12 5 5 <meta name="author" content="z3bra"> 6 6 <meta name="viewport" content="width=device-width"> 7 <link rel="icon" type="image/png" href="/favicon.png" />8 7 <title>Partage</title> 9 8 </head> … … 14 13 limited to {{.Maxsize}}. 15 14 </p> 16 <form >15 <form enctype="multipart/form-data" method="post"> 17 16 <label for="uck">Select file(s) to share</label> 18 <input id="uck" type="file" multiple=true/> 17 <input id="uck" name="uck" type="file" multiple/> 18 <input id="output" name="output" type="hidden" value='html' /> 19 19 <input type="submit" value="Upload!"/> 20 20 </form> 21 21 </body> 22 </html>
Note:
See TracChangeset
for help on using the changeset viewer.