Skip to content

Commit

Permalink
Add file upload functionality and print request details
Browse files Browse the repository at this point in the history
  • Loading branch information
sschonss committed Jan 9, 2024
1 parent 340c76f commit ff22575
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ print_log.txt
/.idea/modules.xml
/.idea/vcs.xml
/server/print_log.txt
/files
8 changes: 6 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,16 @@ 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)

Check failure on line 25 in main.go

View workflow job for this annotation

GitHub Actions / build

fmt.Fprintf format %s has arg r of wrong type *net/http.Request
if err != nil {
log.Println(err)
fmt.Fprintf(w, "Error parsing form: %s\n", err)
return
}

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)
Expand All @@ -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)
Expand Down

0 comments on commit ff22575

Please sign in to comment.