小智 5
这里有多个问题。
您的 tus 库导入路径是错误的,它们应该是:
"github.com/tus/tusd/pkg/handler"
"github.com/tus/tusd/pkg/s3store"
Run Code Online (Sandbox Code Playgroud)
您没有正确使用 S3 存储,您设置了一个配置来直接在服务器上存储
fStore := filestore.FileStore{
Path: "./uploads",
}
Run Code Online (Sandbox Code Playgroud)
相反,它应该是这样的:
// 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))
}
Run Code Online (Sandbox Code Playgroud)
您的客户端也可能无法正常工作(我没有测试它)。
我建议您使用https://github.com/eventials/go-tus而不是尝试自己实现该协议。