From ff22575e0926a098fe7e6eb9c78677d16e27d0d3 Mon Sep 17 00:00:00 2001 From: schons Date: Tue, 9 Jan 2024 17:16:56 -0300 Subject: [PATCH] Add file upload functionality and print request details --- .gitignore | 1 + main.go | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index cd892d6..d902ea6 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ print_log.txt /.idea/modules.xml /.idea/vcs.xml /server/print_log.txt +/files diff --git a/main.go b/main.go index b124847..3b62d6f 100644 --- a/main.go +++ b/main.go @@ -21,7 +21,8 @@ func enableCors(w *http.ResponseWriter) { func printImage(w http.ResponseWriter, r *http.Request) { enableCors(&w) - err := r.ParseMultipartForm(10 << 20) // Ajuste o tamanho máximo do arquivo conforme necessário + err := r.ParseMultipartForm(10 << 20) + fmt.Fprintf(w, "Request: %s\n", r) if err != nil { log.Println(err) fmt.Fprintf(w, "Error parsing form: %s\n", err) @@ -29,6 +30,7 @@ func printImage(w http.ResponseWriter, r *http.Request) { } file, handler, err := r.FormFile("image") + fmt.Fprintf(w, "File: %s\n", file) if err != nil { log.Println(err) fmt.Fprintf(w, "Error retrieving the file: %s\n", err) @@ -37,7 +39,9 @@ func printImage(w http.ResponseWriter, r *http.Request) { defer file.Close() imageName := handler.Filename - imagePath := "./files/" + imageName // Diretório onde as imagens serão salvas + fmt.Fprintf(w, "Image name: %s\n", imageName) + imagePath := "./files/" + imageName + fmt.Fprintf(w, "Image path: %s\n", imagePath) outputFile, err := os.Create(imagePath) if err != nil { log.Println(err)