Skip to content

Commit

Permalink
add x-use-path-as-id header
Browse files Browse the repository at this point in the history
  • Loading branch information
peifan-tes committed Oct 15, 2020
1 parent 86bc044 commit 615f834
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions pkg/handler/unrouted_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -371,11 +371,16 @@ func (handler *UnroutedHandler) PostFile(w http.ResponseWriter, r *http.Request)

// Add the Location header directly after creating the new resource to even
// include it in cases of failure when an error is returned
var filename = "unknow.filename"
if v := info.MetaData["filename"]; strings.Trim(v, " ") != "" {
filename = filepath.Base(strings.Trim(v, " "))
url := handler.absFileURL(r, id)

if r.Header.Get("x-use-path-as-id") != "true" {
var filename = "unknow.filename"
if v := info.MetaData["filename"]; strings.Trim(v, " ") != "" {
filename = filepath.Base(strings.Trim(v, " "))
}
url += "/" + url2.PathEscape(filename)
}
url := handler.absFileURL(r, id) + "/" + url2.PathEscape(filename)

w.Header().Set("Location", url)

handler.Metrics.incUploadsCreated()
Expand Down

0 comments on commit 615f834

Please sign in to comment.