【问题标题】:Golang HTTP uploading file to S3 using tusd only uploading metadataGolang HTTP 上传文件到 S3 使用 tusd 仅上传元数据
【发布时间】:2020-01-15 01:38:33
【问题描述】:

我正在使用 tusd 库将文件直接上传到 Go 中的 S3。它似乎正在运行,但是 tusd 上传了两个文件,一个 .info 元数据文件和一个 .bin 实际内容文件。出于某种原因,我的代码只是上传信息文件。 该文档很难导航,所以也许我错过了某处的设置

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

【问题讨论】:

    标签: go amazon-s3 upload tus


    【解决方案1】:

    这里有多个问题。

    您的 tus 库导入路径错误,应该是:

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

    你没有正确使用 S3 存储,你设置了一个配置来直接在你的服务器上存储

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

    相反,它应该是这样的:

    // 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))
     }
    

    您的客户端也可能工作不正常(我没有测试过)。

    我建议你使用https://github.com/eventials/go-tus,而不是尝试自己实现协议。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-08-20
      • 1970-01-01
      • 1970-01-01
      • 2021-03-02
      • 2013-10-16
      • 1970-01-01
      • 2013-10-28
      相关资源
      最近更新 更多