LordMate
Intern
Intern
  • UID8391
  • Fans0
  • Follows0
  • Posts1
Reads:6673Replies:1

[ASK] OSS 405 Not Allowed

Created#
More Posted time:Dec 5, 2019 18:13 PM
Hello master..
all codes is running well in localhost, i can put object to OSS.

but i can't put object to OSS from my instance in AWS,
error message : oss: service returned invalid response body, status = 405 Not Allowed, RequestId =
i already setting my bucket to public read and write


Thanks..





err = oss.UploadImage(“driver/image/myImage.jpg”, driverRequest.ImageStnk)




==my package==

package oss

import (
"bytes"
"encoding/base64"
"errors"
"os"
"strings"

"github.com/aliyun/aliyun-oss-go-sdk/oss"
)

// Upload file
func Upload(bucketName string, name string, file string) error {
// Create an OSSClient instance.
client, err := oss.New(os.Getenv("OSS_ENDPOINT"), os.Getenv("OSS_ACCESS_KEY_ID"), os.Getenv("OSS_ACCESS_KEY_SECRET"))
if err != nil {
return err
}

// Obtain the bucket.
bucket, err := client.Bucket(bucketName)
if err != nil {
return err
}

// image validation.
i := strings.Index(file, ",")
if i < 0 {
return errors.New("Please suplay valid base64 file")
}

i2 := strings.Index(file, ";")
if i2 < 0 {
return errors.New("Please suplay valid base64 file")
}

obj, err := base64.StdEncoding.DecodeString(file[i+1:])
if err != nil {
return err
}

return bucket.PutObject(name, bytes.NewReader(obj))
}

// UploadVideo to OSS
func UploadVideo(name string, file string) error {
return Upload(os.Getenv("OSS_BUCKET_VIDEO"), name, file)
}

// UploadImage to OSS
func UploadImage(name string, file string) error {
return Upload(os.Getenv("OSS_BUCKET_IMAGE"), name, file)
}

// UploadDocument to OSS
func UploadDocument(name string, file string) error {
return Upload(os.Getenv("OSS_BUCKET_DOCUMENT"), name, file)
}

afzaalvirgoboy
Assistant Engineer
Assistant Engineer
  • UID6091
  • Fans1
  • Follows0
  • Posts49
1st Reply#
Posted time:Dec 6, 2019 20:19 PM
Hi,


The HTTP error of 405 means that the specified method is not allowed on the resource. Can you check with the Go SDK to verify that you are doing exactly what is allowed on the OSS resources under Go SDK?


https://github.com/aliyun/aliyun-oss-go-sdk


If you are using the Go SDK to upload the file -- and not using a custom function -- then please create a new issue so that the Alibaba Cloud SDK team can help you out, https://github.com/aliyun/aliyun-oss-go-sdk/issues. Otherwise, if you are using your own code to do this, then I highly recommend that you read the documentation to learn what HTTP methods and verbs are allowed on what resources.


Check out this resource, https://www.alibabacloud.com/help/doc-detail/55538.htm


Read this blog to understand what this error means:https://airbrake.io/blog/http-errors/405-method-not-allowed
Guest