1

I'm creating a simple application where it allows users to upload big files using simple-uploader since this plugin sends the files in chunks instead of one big file. The problem is that when I save the file the first chunk is the only one that is being saved. Is there a way in Go where I'll wait for all the chunks to arrive in the server then save it afterward?

Here's a snippet of the code I'm doing:

    dFile, err := c.FormFile("file")
    if err != nil {
        return SendError(c, err)
    }

    filename := dFile.Filename
    f, err := dFile.Open()

    if err != nil {
        return SendError(c, err)
    }
    defer f.Close()

    // save file in s3
    duration := sss.UploadFile(f, "temp/"+filename")
    ... send response

By the way for this project, I'm using the fiber framework.

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
ginad
  • 1,863
  • 2
  • 27
  • 42
  • To be honest, I had no idea. Here is what I found on the topic so far: https://stackoverflow.com/questions/40684307/how-can-i-receive-an-uploaded-file-using-a-golang-net-http-server, but that's what you are already doing, right? – TehSphinX Dec 25 '20 at 15:49
  • Did you also use the `ParseMultiPartForm` function of `http.Request`? – TehSphinX Dec 25 '20 at 15:53
  • do you mean you have used this https://github.com/simple-uploader/Uploader ? –  Dec 25 '20 at 16:40

1 Answers1

0

While working on this I encountered tus-js-client which is doing the same as the simple-uploader and implementation in go called tusd which will reassemble the chunks so you don't have to worry about it anymore.

Here's a discussion where I posted my solution: https://stackoverflow.com/a/65785097/549529.

ginad
  • 1,863
  • 2
  • 27
  • 42