skip to Main Content

i am developing a preview function where i want to view objects from my s3 aws bucket. i get this url: https://[BUCKET NAME].s3.us-east-2.amazonaws.com/[FILE NAME].[EXTENTION] and when i open it the file automatically starts to download whereas i just want to view the file not download it as an attachment.

i have tried google viewer url: https://docs.google.com/viewerng/viewer?url=https://[BUCKET NAME].s3.us-east-2.amazonaws.com/[FILE NAME].[EXTENTION]&chrome=false . it works fine but i was asked specifically to find a way to view thru aws url as the google viewer at times is not loading fast and also leaves the screen blank for a long time.

2

Answers


  1. Here is some server side set up need to required.
    While upload file into AWS S3 Bucket set below configuration.

    In Spring Boot Java

    AmazonS3 amazonS3;// define bean in configuration file
    
    // put file into bucket and get public URL for it by that we can access it
    
    amazonS3.putObject(new PutObjectRequest(bucketName, fileName, file).withCannedAcl(CannedAccessControlList.PublicRead)); 
    // get public URL
    fileUrl = String.valueOf(amazonS3.getUrl(bucketName, fileName));
    
    Login or Signup to reply.
  2. It Depands upon extension of the file you try to access via url. extension with img and mp4 can easily view in webpage without any confusion. if you want to access file with other extension like html,css,javascript you can try using static-web-hosting in s3.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search