@@ -34,7 +34,6 @@ func uploadFileHandler() http.HandlerFunc {
34
34
}
35
35
36
36
// parse and validate file and post parameters
37
- fileType := r .PostFormValue ("type" )
38
37
file , _ , err := r .FormFile ("uploadFile" )
39
38
if err != nil {
40
39
renderError (w , "INVALID_FILE" , http .StatusBadRequest )
@@ -48,8 +47,8 @@ func uploadFileHandler() http.HandlerFunc {
48
47
}
49
48
50
49
// 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 {
53
52
case "image/jpeg" , "image/jpg" :
54
53
case "image/gif" , "image/png" :
55
54
case "application/pdf" :
@@ -59,13 +58,13 @@ func uploadFileHandler() http.HandlerFunc {
59
58
return
60
59
}
61
60
fileName := randToken (12 )
62
- fileEndings , err := mime .ExtensionsByType (fileType )
61
+ fileEndings , err := mime .ExtensionsByType (detectedFileType )
63
62
if err != nil {
64
63
renderError (w , "CANT_READ_FILE_TYPE" , http .StatusInternalServerError )
65
64
return
66
65
}
67
66
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 )
69
68
70
69
// write file
71
70
newFile , err := os .Create (newPath )
0 commit comments