| 378 | } |
| 379 | |
| 380 | func (mod *RestAPI) readFile(fileName string, w http.ResponseWriter, r *http.Request) { |
| 381 | fp, err := os.Open(fileName) |
| 382 | if err != nil { |
| 383 | msg := fmt.Sprintf("could not open %s for reading: %s", fileName, err) |
| 384 | mod.Debug(msg) |
| 385 | http.Error(w, msg, 404) |
| 386 | return |
| 387 | } |
| 388 | defer fp.Close() |
| 389 | |
| 390 | w.Header().Set("Content-type", "application/octet-stream") |
| 391 | |
| 392 | io.Copy(w, fp) |
| 393 | } |
| 394 | |
| 395 | func (mod *RestAPI) writeFile(fileName string, w http.ResponseWriter, r *http.Request) { |
| 396 | data, err := io.ReadAll(r.Body) |