PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, July 31, 2022

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

 July 31, 2022     amazon-s3, file-upload, go     No comments   

Issue

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?

Thanks


Solution

You can construct the URL as:

https://BUCKETNAME.s3-REGIONNAME.amazonaws.com/KEY

For example:

https://my-bucket.s3-ap-southeast-2.amazonaws.com/foo/bar.txt


Answered By - John Rotenstein
Answer Checked By - Marilyn (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing