How do I get file url after put file to amazon s3 in Go?


File is uploaded successfully, and I want to return file url after uploading.

_, err := s3.New(s).PutObject(&s3.PutObjectInput{
    Bucket:               aws.String("bucket"),
    Key:                  aws.String(tempFileName),
    ACL:                  aws.String("public-read"), // could be private if you want it to be access by only authorized users
    Body:                 bytes.NewReader(buffer),
    ContentLength:        aws.Int64(int64(size)),
    ContentType:          aws.String(http.DetectContentType(buffer)),
    ContentDisposition:   aws.String("attachment"),
    ServerSideEncryption: aws.String("AES256"),
    StorageClass:         aws.String("INTELLIGENT_TIERING"),

I have checked amazon doc for PutObject function, but PutObjectOutput struct type
But there is no uploaded file url in this structure.

How can I get file url?
Is there other way to return uploaded file url in amazon s3 sdk as soon as upload success?



You can construct the URL as:

For example:

Answered By – John Rotenstein

Answer Checked By – Mildred Charles (GoLangFix Admin)

Leave a Reply

Your email address will not be published.