doolo00026 2018-05-12 07:44
浏览 175

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
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 MATLAB动图问题
    • ¥15 【提问】基于Invest的水源涵养
    • ¥20 微信网友居然可以通过vx号找到我绑的手机号
    • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
    • ¥15 解riccati方程组
    • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
    • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
    • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
    • ¥50 树莓派安卓APK系统签名
    • ¥65 汇编语言除法溢出问题