Skip to content

Commit 68a1727

Browse files
committed
Update Backend on Go.md
1 parent 8bab785 commit 68a1727

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

samples/Backend on Go.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# Backend in Go
22

3-
Each `POST` request is parsed and then saved to disk. After the final chunk is uploaded, the chunks are stitched together in a separate go routine and then deleted.
3+
1. A `GET` request is sent to see if a chunk exists on disk. If it isn't found, the chunk is uploaded.
4+
2. Each `POST` request is parsed and then saved to disk.
5+
3. After the final chunk is uploaded, the chunks are stitched together in a separate go routine.
6+
4. The chunks are deleted.
47

58
This implementation assumes that the final chunk is the last piece of the file being uploaded.
69

@@ -42,6 +45,7 @@ func main() {
4245
})
4346

4447
m.Post("/upload", streamHandler(chunkedReader))
48+
m.Get("/upload", continueUpload)
4549

4650
m.Run()
4751
}
@@ -64,6 +68,14 @@ func (fn streamHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
6468
}
6569
}
6670

71+
func continueUpload(w http.ResponseWriter, r *http.Request) {
72+
chunkDirPath := "./incomplete/" + r.FormValue("flowFilename") + "/" + r.FormValue("flowChunkNumber")
73+
if _, err := os.Stat(chunkDirPath); err != nil {
74+
w.WriteHeader(404)
75+
return
76+
}
77+
}
78+
6779
func chunkedReader(w http.ResponseWriter, r *http.Request) error {
6880
r.ParseMultipartForm(25)
6981

0 commit comments

Comments
 (0)