diff --git a/src/cmd/tusd/data.go b/src/cmd/tusd/data.go index 0dc996d..1f7470e 100644 --- a/src/cmd/tusd/data.go +++ b/src/cmd/tusd/data.go @@ -95,7 +95,6 @@ func getReceivedChunks(fileId string) (chunkSet, error) { } lines := strings.Split(string(data), "\n") - chunks := make(chunkSet, 0, len(lines)-1) for i, line := range lines { // last line is always empty, skip it @@ -105,17 +104,17 @@ func getReceivedChunks(fileId string) (chunkSet, error) { parts := strings.Split(line, ",") if len(parts) != 2 { - return nil, errors.New("getReceivedChunks: corrupt log line: "+line) + return nil, errors.New("getReceivedChunks: corrupt log line: " + line) } start, err := strconv.ParseInt(parts[0], 10, 64) if err != nil { - return nil, errors.New("getReceivedChunks: invalid start: "+parts[0]) + return nil, errors.New("getReceivedChunks: invalid start: " + parts[0]) } end, err := strconv.ParseInt(parts[1], 10, 64) if err != nil { - return nil, errors.New("getReceivedChunks: invalid end: "+parts[1]) + return nil, errors.New("getReceivedChunks: invalid end: " + parts[1]) } chunks.Add(chunk{Start: start, End: end}) diff --git a/src/cmd/tusd/http.go b/src/cmd/tusd/http.go index fee2772..33602da 100644 --- a/src/cmd/tusd/http.go +++ b/src/cmd/tusd/http.go @@ -61,11 +61,6 @@ func postFiles(w http.ResponseWriter, r *http.Request) { return } - if contentRange.End != -1 { - reply(w, http.StatusNotImplemented, "File data in initial request.") - return - } - contentType := r.Header.Get("Content-Type") if contentType == "" { contentType = "application/octet-stream" @@ -77,9 +72,16 @@ func postFiles(w http.ResponseWriter, r *http.Request) { 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) + setFileRangeHeader(w, id) w.WriteHeader(http.StatusCreated) }