Support data in initial PUT

This commit is contained in:
Felix Geisendörfer 2013-03-18 18:26:44 +01:00
parent 34d69e6937
commit 04184d26ed
2 changed files with 11 additions and 10 deletions

View File

@ -95,7 +95,6 @@ func getReceivedChunks(fileId string) (chunkSet, error) {
} }
lines := strings.Split(string(data), "\n") lines := strings.Split(string(data), "\n")
chunks := make(chunkSet, 0, len(lines)-1) chunks := make(chunkSet, 0, len(lines)-1)
for i, line := range lines { for i, line := range lines {
// last line is always empty, skip it // last line is always empty, skip it

View File

@ -61,11 +61,6 @@ func postFiles(w http.ResponseWriter, r *http.Request) {
return return
} }
if contentRange.End != -1 {
reply(w, http.StatusNotImplemented, "File data in initial request.")
return
}
contentType := r.Header.Get("Content-Type") contentType := r.Header.Get("Content-Type")
if contentType == "" { if contentType == "" {
contentType = "application/octet-stream" contentType = "application/octet-stream"
@ -77,9 +72,16 @@ func postFiles(w http.ResponseWriter, r *http.Request) {
return return
} }
// @TODO: Return X-Missing header if contentRange.End != -1 {
if err := putFileChunk(id, contentRange.Start, contentRange.End, r.Body); err != nil {
// @TODO: Could be a 404 as well
reply(w, http.StatusInternalServerError, err.Error())
return
}
}
w.Header().Set("Location", "/files/"+id) w.Header().Set("Location", "/files/"+id)
setFileRangeHeader(w, id)
w.WriteHeader(http.StatusCreated) w.WriteHeader(http.StatusCreated)
} }