From 37f9a0cbbc53a484ef7a415b1f813e5a5d1620f8 Mon Sep 17 00:00:00 2001 From: andreimarcu Date: Sat, 25 Mar 2017 08:44:18 -0700 Subject: [PATCH] Change unknown extension from .ext to .file --- server_test.go | 12 ++++++------ upload.go | 8 ++++---- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/server_test.go b/server_test.go index a590465..6fe363c 100644 --- a/server_test.go +++ b/server_test.go @@ -699,7 +699,7 @@ func TestPutUpload(t *testing.T) { mux := setup() w := httptest.NewRecorder() - filename := generateBarename() + ".ext" + filename := generateBarename() + ".file" req, err := http.NewRequest("PUT", "/upload/"+filename, strings.NewReader("File content")) if err != nil { @@ -717,7 +717,7 @@ func TestPutRandomizedUpload(t *testing.T) { mux := setup() w := httptest.NewRecorder() - filename := generateBarename() + ".ext" + filename := generateBarename() + ".file" req, err := http.NewRequest("PUT", "/upload/"+filename, strings.NewReader("File content")) if err != nil { @@ -757,7 +757,7 @@ func TestPutEmptyUpload(t *testing.T) { mux := setup() w := httptest.NewRecorder() - filename := generateBarename() + ".ext" + filename := generateBarename() + ".file" req, err := http.NewRequest("PUT", "/upload/"+filename, strings.NewReader("")) if err != nil { @@ -779,7 +779,7 @@ func TestPutJSONUpload(t *testing.T) { mux := setup() w := httptest.NewRecorder() - filename := generateBarename() + ".ext" + filename := generateBarename() + ".file" req, err := http.NewRequest("PUT", "/upload/"+filename, strings.NewReader("File content")) if err != nil { @@ -806,7 +806,7 @@ func TestPutRandomizedJSONUpload(t *testing.T) { mux := setup() w := httptest.NewRecorder() - filename := generateBarename() + ".ext" + filename := generateBarename() + ".file" req, err := http.NewRequest("PUT", "/upload/"+filename, strings.NewReader("File content")) if err != nil { @@ -834,7 +834,7 @@ func TestPutExpireJSONUpload(t *testing.T) { mux := setup() w := httptest.NewRecorder() - filename := generateBarename() + ".ext" + filename := generateBarename() + ".file" req, err := http.NewRequest("PUT", "/upload/"+filename, strings.NewReader("File content")) if err != nil { diff --git a/upload.go b/upload.go index bd2bed6..9cf8713 100644 --- a/upload.go +++ b/upload.go @@ -219,11 +219,11 @@ func processUpload(upReq UploadRequest) (upload Upload, err error) { // Determine the type of file from header kind, err := filetype.Match(header) - if err != nil { - extension = "ext" + if err != nil || kind.Extension == "unknown" { + extension = "file" + } else { + extension = kind.Extension } - - extension = kind.Extension } upload.Filename = strings.Join([]string{barename, extension}, ".")