tus / tusd

Reference server implementation in Go of tus: the open protocol for resumable file uploads
https://tus.github.io/tusd
MIT License
3.08k stars 483 forks source link

Error: tus: invalid or missing offset value, originated from request #1176

Closed holedaemon closed 2 months ago

holedaemon commented 2 months ago

Describe the bug I am programmatically embedding tusd into my Go backend using the instructions found here. When I attempt to upload large files from my frontend, I am met with the following error. I do not have my backend running behind any proxies when doing this.

image

To Reproduce Steps to reproduce the behavior:

  1. Setup tusd.
    
    tusstore := filestore.New(s.tusDir)
    locker := filelocker.New(s.tusDir)
    composer := tus.NewStoreComposer()
    tusstore.UseIn(composer)
    locker.UseIn(composer)

handler, err := tus.NewHandler(tus.Config{ BasePath: "/tus/", StoreComposer: composer, NotifyCompleteUploads: true, }) if err != nil { return fmt.Errorf("creating tus handler: %w", err) }

go func() { for { select { case <-ctx.Done(): return case event := <-handler.CompleteUploads: ctxlog.Info(ctx, "upload complete", zap.String("id", event.Upload.ID)) } } }()

2. Initialize handlers.
```go
r.Handle("/tus/", http.StripPrefix("/tus/", handler))
r.Handle("/tus", http.StripPrefix("/tus", handler))
  1. Launch server and upload file on the frontend.

Expected behavior Files should be uploaded to the server.

Setup details Please provide following details, if applicable to your situation:

If I am lacking any needed information please let me know. I've dug through issues, code, etc to try and resolve this myself and I'm coming up short. I'm not sure if it's something I'm doing or what, but I appreciate any guidance. Thank you

holedaemon commented 2 months ago

I have done some further testing and noticed that when using tusd programmatically, I am not seeing any of the Upload-* headers in my requests to the server from the browser, but when I run tusd as a Docker container and upload to that, I am seeing the correct headers & the upload succeeds. Something must be wrong with my implementation.

holedaemon commented 2 months ago

After many hours, I came to the embarrassing realization that the culprit was how I had my paths set up on my mux.

I changed

r.Handle("/tus/", http.StripPrefix("/tus/", handler))

to

r.Handle("/tus/*", http.StripPrefix("/tus/", handler))

and uploads work fine.

Sorry for the trouble. I'm going to drive into a ditch.

Thanks