我使用Golang作为我的后端代码,我有一个应用程序,允许人们上传图像和视频。我有图像工作和视频用于工作但现在由于某种原因我得到这个错误,这与这个https://github.com/aws/aws-sdk-js/issues/15相同。我已经检查过并且视频正在越过,因为返回的文件有一些大小但由于某种原因我在上传视频时仍然收到以下错误...错误发生在 PutObject 以下任何建议都会很棒
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")
}
错误:
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