tus / tusd

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

While passing s3Client to s3store.New getting an error named missing method AbortMultipartUploadWithContext #1139

Closed souravlayek closed 1 month ago

souravlayek commented 1 month ago

Describe the bug I am trying to implement resumable upload in my go server with s3 bucket, But while doing the setup I came to an error missing method AbortMultipartUploadWithContext. When I dig deep I found that the S3API interface type has one method missing that s3Client has.

Here is my code:

package main

import (
    "context"
    "fmt"
    "github.com/aws/aws-sdk-go-v2/aws"
    "github.com/aws/aws-sdk-go-v2/config"
    "github.com/aws/aws-sdk-go-v2/service/s3"
    // "github.com/tus/tusd"
    "github.com/tus/tusd/pkg/handler"
    "github.com/tus/tusd/pkg/s3store"
    "log"
    "net/http"
)

func connectS3() *s3.Client {
    cfg, err := config.LoadDefaultConfig(context.TODO(), config.WithRegion("us-east-1"))
    if err != nil {
        log.Fatal(err)
    }
    client := s3.NewFromConfig(cfg)
    return client
}
func main() {
    s3Client := connectS3()
    bucket := "mittler-storage"

    // Create S3 store
    store := s3store.New(bucket, s3Client)
    // Create a new tusd handler using the S3 store
    composer := handler.NewStoreComposer()
    store.UseIn(composer)
    config := handler.Config{
        StoreComposer:           composer,
        BasePath:                "/files/",
        NotifyCompleteUploads:   true,
        NotifyTerminatedUploads: true,
        NotifyUploadProgress:    true,
        RespectForwardedHeaders: true,
    }

    handler, err := handler.NewHandler(config)
    if err != nil {
        log.Fatalf("unable to create tusd handler, %v", err)
    }

    apiRouter := http.NewServeMux()
    apiRouter.Handle("/upload-video/", http.StripPrefix("/upload-video", handler))
    server := http.Server{
        Addr:    ":8000",
        Handler: apiRouter,
    }
    fmt.Println("Server is running on port 8000")
    log.Fatal(server.ListenAndServe())
}

The Error I got

./main.go:29:31: cannot use s3Client (variable of type *"github.com/aws/aws-sdk-go-v2/service/s3".Client) as s3store.S3API value in argument to s3store.New: *"github.com/aws/aws-sdk-go-v2/service/s3".Client does not implement s3store.S3API (missing method AbortMultipartUploadWithContext)

To Reproduce Steps to reproduce the behavior:

  1. Copy the go code to one go file
  2. Import the necessary packages (those are used in imports)
  3. In console you will get the error.

Expected behavior Based on the repo and source code available in repo, I think passing s3Client to s3store.New method.

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

Acconut commented 1 month ago

You are importing tusd v1, which is only compatible with AWS SDK for Go v1. But you are passing the AWS SDK for Go v2 to tusd v1, which does not work. You should upgrade to tusd v2 by using those imports:

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

tusd v1 is also no longer supported by us.

souravlayek commented 1 month ago

Thanks I have updated packages and it is working