Change unknown extension from .ext to .file

This commit is contained in:
andreimarcu 2017-03-25 08:44:18 -07:00
parent 1c1d3127ab
commit 37f9a0cbbc
2 changed files with 10 additions and 10 deletions

View File

@ -699,7 +699,7 @@ func TestPutUpload(t *testing.T) {
mux := setup() mux := setup()
w := httptest.NewRecorder() w := httptest.NewRecorder()
filename := generateBarename() + ".ext" filename := generateBarename() + ".file"
req, err := http.NewRequest("PUT", "/upload/"+filename, strings.NewReader("File content")) req, err := http.NewRequest("PUT", "/upload/"+filename, strings.NewReader("File content"))
if err != nil { if err != nil {
@ -717,7 +717,7 @@ func TestPutRandomizedUpload(t *testing.T) {
mux := setup() mux := setup()
w := httptest.NewRecorder() w := httptest.NewRecorder()
filename := generateBarename() + ".ext" filename := generateBarename() + ".file"
req, err := http.NewRequest("PUT", "/upload/"+filename, strings.NewReader("File content")) req, err := http.NewRequest("PUT", "/upload/"+filename, strings.NewReader("File content"))
if err != nil { if err != nil {
@ -757,7 +757,7 @@ func TestPutEmptyUpload(t *testing.T) {
mux := setup() mux := setup()
w := httptest.NewRecorder() w := httptest.NewRecorder()
filename := generateBarename() + ".ext" filename := generateBarename() + ".file"
req, err := http.NewRequest("PUT", "/upload/"+filename, strings.NewReader("")) req, err := http.NewRequest("PUT", "/upload/"+filename, strings.NewReader(""))
if err != nil { if err != nil {
@ -779,7 +779,7 @@ func TestPutJSONUpload(t *testing.T) {
mux := setup() mux := setup()
w := httptest.NewRecorder() w := httptest.NewRecorder()
filename := generateBarename() + ".ext" filename := generateBarename() + ".file"
req, err := http.NewRequest("PUT", "/upload/"+filename, strings.NewReader("File content")) req, err := http.NewRequest("PUT", "/upload/"+filename, strings.NewReader("File content"))
if err != nil { if err != nil {
@ -806,7 +806,7 @@ func TestPutRandomizedJSONUpload(t *testing.T) {
mux := setup() mux := setup()
w := httptest.NewRecorder() w := httptest.NewRecorder()
filename := generateBarename() + ".ext" filename := generateBarename() + ".file"
req, err := http.NewRequest("PUT", "/upload/"+filename, strings.NewReader("File content")) req, err := http.NewRequest("PUT", "/upload/"+filename, strings.NewReader("File content"))
if err != nil { if err != nil {
@ -834,7 +834,7 @@ func TestPutExpireJSONUpload(t *testing.T) {
mux := setup() mux := setup()
w := httptest.NewRecorder() w := httptest.NewRecorder()
filename := generateBarename() + ".ext" filename := generateBarename() + ".file"
req, err := http.NewRequest("PUT", "/upload/"+filename, strings.NewReader("File content")) req, err := http.NewRequest("PUT", "/upload/"+filename, strings.NewReader("File content"))
if err != nil { if err != nil {

View File

@ -219,12 +219,12 @@ func processUpload(upReq UploadRequest) (upload Upload, err error) {
// Determine the type of file from header // Determine the type of file from header
kind, err := filetype.Match(header) kind, err := filetype.Match(header)
if err != nil { if err != nil || kind.Extension == "unknown" {
extension = "ext" extension = "file"
} } else {
extension = kind.Extension extension = kind.Extension
} }
}
upload.Filename = strings.Join([]string{barename, extension}, ".") upload.Filename = strings.Join([]string{barename, extension}, ".")
upload.Filename = strings.Replace(upload.Filename, " ", "", -1) upload.Filename = strings.Replace(upload.Filename, " ", "", -1)