1

I am using the tusd library to upload a file directly to S3 in Go. It seems to be functioning however tusd uploads two files a .info metadata file and a .bin actual content file. For some reason my code is only uploading the info file. The documentation is quite tricky to navigate so perhaps I have missed a setting somewhere

Code as gist to show both the server and the client code.

amlwwalker
  • 2,866
  • 2
  • 20
  • 34

1 Answers1

4

There are mutiple issues here.

Your tus libary import paths are wrong they should be:

    "github.com/tus/tusd/pkg/handler"
    "github.com/tus/tusd/pkg/s3store"

You dont use the S3 store propely, you setup a configuration to have storage directly on your server

fStore := filestore.FileStore{
        Path: "./uploads",
    }

Instead it should be something like this:

// S3 acces configuration
 s3Config := &aws.Config{
     Region:      aws.String(os.Getenv("AWS_REGION")),
     Credentials: credentials.NewStaticCredentials(os.Getenv("AWS_ACCESS_KEY_ID"), os.Getenv("AWS_SECRET_ACCESS_KEY"), ""),
     DisableSSL:       aws.Bool(true),
     S3ForcePathStyle: aws.Bool(true),
 }

// Setting up the s3 storage
 s3Store := s3store.New(os.Getenv("AWS_BUCKET_NAME"), s3.New(session.Must(session.NewSession()), s3Config))

// Creates a new and empty store composer   
 composer := handler.NewStoreComposer()
// UseIn sets this store as the core data store in the passed composer and adds all possible extension to it.
 s3Store.UseIn(composer)

// Setting up handler
 handler, err := handler.NewHandler(handler.Config{
     BasePath:                "/files/",
     StoreComposer:           composer,
 })
 if err != nil {
     panic(fmt.Errorf("Unable to create handler: %s", err))
 }

// Listen and serve
 http.Handle("/files/", http.StripPrefix("/files/", handler))
 err = http.ListenAndServe(":8080", nil)
 if err != nil {
     panic(fmt.Errorf("Unable to listen: %s", err))
 }

It is possible that your client isnt working proprely also (I didnt test it).

I would recommend you use https://github.com/eventials/go-tus instead of trying to implement the protocol by yourself.