Golang Amazon S3视频上传出现奇怪的错误

I am using Golang as my backend code, I have an app that allows people to upload images and videos. I have images working and videos used to work but now for some reason I am getting this error which is the same as this one https://github.com/aws/aws-sdk-js/issues/15 . I have checked and the video is crossing over since the file that is being returned has some size but for some reason I keep getting the error below when it comes to uploading videos ... The error occurs in the PutObject below any suggestions would be great

func UploadStreamVideo(w http.ResponseWriter, r *http.Request) {
    r.ParseForm()

    var buf bytes.Buffer
    sess, _ := session.NewSession(&aws.Config{
        Region:      aws.String("us-west-2"),
        Credentials: credentials.NewStaticCredentials(aws_access_key_id, aws_secret_access_key, ""),
    })

    svc := s3.New(sess)

    file, handler, err := r.FormFile("file")
    if err != nil {
        log_errors("HomePage-UploadStreamImage: error receiving file", err.Error(), w)
        fmt.Println("Error Uploading Image")
        return
    }
    defer file.Close()
    println(handler.Filename) // I can see filename
    println(handler.Size)   // I also see the size here

    read_file, err := ioutil.ReadAll(file)

    if err != nil {
        log_errors("HomePage-UploadStreamImage")
        return
    }

    file.Read(read_file)
    fileBytes := bytes.NewReader(read_file)
    fileSize, err := buf.ReadFrom(file)
    if err != nil {
        log_errors("HomePage-UploadStreamImage")
    }

    fileType := http.DetectContentType(read_file)
    path := handler.Filename

    params := &s3.PutObjectInput{
        Bucket: aws.String("yisl"),
        Key:    aws.String(path),
        Body:   fileBytes,

        ContentLength: aws.Int64(fileSize),
        ContentType:   aws.String(fileType),
    }

     // This code below gives the error
    _, err = svc.PutObject(params)
    if err != nil {
        println(err.Error())
        log_errors("HomePage-UploadStreamImage")
        return
    }

    io.WriteString(w, "Done")
}

And the error:

NotImplemented: A header you provided implies functionality that is
not implemented     status code: 501, request id: 310D0CE7643E1B4B, host
id:
GUB8UDi9KJTIPybXh3I1m5Vu8Ixyt4LQv5PbVnyOH2ngAdtOv0DsyALHp1mMI3SmRpK+xHV3uds=

> 2018/05/12 03:30:21 http: panic serving [::1]:64945: runtime error:
> invalid memory address or nil pointer dereference goroutine 10
> [running]: net/http.(*conn).serve.func1(0xc420229400)
>   /usr/local/go/src/net/http/server.go:1726 +0xd0 panic(0x1451b20,
> 0x1752c30)    /usr/local/go/src/runtime/panic.go:502 +0x229
> database/sql.(*Rows).close(0x0, 0x0, 0x0, 0x0, 0x0)
>   /usr/local/go/src/database/sql/sql.go:2907 +0x6b
> database/sql.(*Rows).Close(0x0, 0x14f5698, 0x4d)
>   /usr/local/go/src/database/sql/sql.go:2903 +0x33
> _/Users/ignaciohernandez/Documents/go/Yisly-Backend/Controllers.log_errors(0x14ef38b,
> 0x2e, 0xc42010aa80, 0xda, 0x15737c0, 0xc420244380)
>   /Users/ignaciohernandez/Documents/go/Yisly-Backend/Controllers/function_store.go:27
> +0x2d8
> _/Users/ignaciohernandez/Documents/go/Yisly-Backend/Controllers.UploadStreamVideo(0x15737c0,
> 0xc420244380, 0xc420211700)
>   /Users/ignaciohernandez/Documents/go/Yisly-Backend/Controllers/HomePage.go:377
> +0x7ad net/http.HandlerFunc.ServeHTTP(0x14fd130, 0x15737c0, 0xc420244380, 0xc420211700)   /usr/local/go/src/net/http/server.go:1947
> +0x44 github.com/gorilla/mux.(*Router).ServeHTTP(0xc420142380, 0x15737c0, 0xc420244380, 0xc420211700)
>   /Users/ignaciohernandez/Documents/go/src/github.com/gorilla/mux/mux.go:162
> +0xed net/http.(*ServeMux).ServeHTTP(0x1760f20, 0x15737c0, 0xc420244380, 0xc420211500)    /usr/local/go/src/net/http/server.go:2337
> +0x130 net/http.serverHandler.ServeHTTP(0xc4201c89c0, 0x15737c0, 0xc420244380, 0xc420211500)  /usr/local/go/src/net/http/server.go:2694
> +0xbc net/http.(*conn).serve(0xc420229400, 0x1573b40, 0xc42002c9c0)   /usr/local/go/src/net/http/server.go:1830 +0x651 created by
> net/http.(*Server).Serve  /usr/local/go/src/net/http/server.go:2795
> +0x27b
dongluan2612
dongluan2612 查看PutObject的AWSS3文档(下面的链接),主体是io.ReadSeeker和r.FormFile(“file”)实现时获得的multipart.File,它实现了io.Reader和io.Seeker,因此我认为您可以通过文件直接发送到PutObject。docs.aws.amazon.com/sdk-for-go/api/service/s3/#PutObjectInput
2 年多之前 回复
doudanma9706
doudanma9706 正如@Flimzy所说,整个过程有点令人困惑。所以我的建议是从一开始就开始清洁东西。首先,是ioutil.ReadAll,然后是file.Read(但是由于ioutil.ReadAll,游标在最后,所以您应该没有字节)。您不需要执行该过程即可获取文件大小,因为您已经有了handler.Size。
2 年多之前 回复
dongsi0625
dongsi0625 您的错误消息有点令人困惑。这就是您所看到的样子吗?还是那两个错误(一个错误,然后是一个堆栈跟踪)?
2 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐