Skip to content

Commit

Permalink
Check for filename before bin
Browse files Browse the repository at this point in the history
This to avoid auto generating a new bin just to abort the request if the filename is not provided. Checking for a missing filename first allows the request to be aborted without generating a new bin.
  • Loading branch information
espebra committed Oct 5, 2024
1 parent 0902f74 commit 3193916
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions http_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,16 +160,17 @@ func (h *HTTP) uploadFile(w http.ResponseWriter, r *http.Request) {
// upload files to / with the request headers bin and filename set instead
// of /{bin}/{filename}
if inputBin == "" || inputFilename == "" {
inputBin = r.Header.Get("bin")
inputFilename = r.Header.Get("filename")
if inputBin == "" {
inputBin = h.dao.Bin().GenerateId()
fmt.Printf("Auto generated bin: %s\n", inputBin)
}
if inputFilename == "" {
h.Error(w, r, "Upload failed: missing filename request header", "Missing filename request header", 952, http.StatusBadRequest)
return
}

inputBin = r.Header.Get("bin")
if inputBin == "" {
inputBin = h.dao.Bin().GenerateId()
fmt.Printf("Auto generated bin: %s\n", inputBin)
}
}

inputMD5 := r.Header.Get("Content-MD5")
Expand Down

0 comments on commit 3193916

Please sign in to comment.