LordMate
Intern
Intern
  • UID8391
  • Fans0
  • Follows0
  • Posts1
Reads:6684Replies: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)
}
Guest