Skip to content

Commit dc190f6

Browse files
committed
fix typo with filetype and remove unused fileType in post
1 parent 454ed13 commit dc190f6

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

main.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ func uploadFileHandler() http.HandlerFunc {
3434
}
3535

3636
// parse and validate file and post parameters
37-
fileType := r.PostFormValue("type")
3837
file, _, err := r.FormFile("uploadFile")
3938
if err != nil {
4039
renderError(w, "INVALID_FILE", http.StatusBadRequest)
@@ -48,8 +47,8 @@ func uploadFileHandler() http.HandlerFunc {
4847
}
4948

5049
// check file type, detectcontenttype only needs the first 512 bytes
51-
filetype := http.DetectContentType(fileBytes)
52-
switch filetype {
50+
detectedFileType := http.DetectContentType(fileBytes)
51+
switch detectedFileType {
5352
case "image/jpeg", "image/jpg":
5453
case "image/gif", "image/png":
5554
case "application/pdf":
@@ -59,13 +58,13 @@ func uploadFileHandler() http.HandlerFunc {
5958
return
6059
}
6160
fileName := randToken(12)
62-
fileEndings, err := mime.ExtensionsByType(fileType)
61+
fileEndings, err := mime.ExtensionsByType(detectedFileType)
6362
if err != nil {
6463
renderError(w, "CANT_READ_FILE_TYPE", http.StatusInternalServerError)
6564
return
6665
}
6766
newPath := filepath.Join(uploadPath, fileName+fileEndings[0])
68-
fmt.Printf("FileType: %s, File: %s\n", fileType, newPath)
67+
fmt.Printf("FileType: %s, File: %s\n", detectedFileType, newPath)
6968

7069
// write file
7170
newFile, err := os.Create(newPath)

0 commit comments

Comments
 (0)