1

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.

This is to be done in flask (python framework). I am using dropzone.js to upload it to my aws. I am also using jquery .

3
  • 1
    What type of file is this? Binary, jpg, pdf? Are you familiar with the purpose of the Content-Disposition header? Commented Apr 23, 2024 at 11:53
  • yes content disposition is what i have tried but i am uploading thru dropzone and it's not so useful. the file types are doc, docx, pdf & wps Commented Apr 24, 2024 at 9:22
  • I have done google viewer in this way now in iframe: '<iframe src=[link]"https://docs.google.com/viewer?url='+IMAGE_UPLOAD_PATH_AWS+''+file[3]+'&embedded=true&chrome=false/edit?&rm=minimal" class="upload-images-box vehicle-img" frameborder="0"></iframe>' and it is working fine but the only issue is the widgets google is giving me inbuilt with the url how do i remove it ? Commented Apr 24, 2024 at 9:24

2 Answers 2

0

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));
Sign up to request clarification or add additional context in comments.

3 Comments

i have a public url to access but when i go on the url it downloads the file instead of viewing it
also sorry for adding in later i am using python not java
if you get the public url using amazonS3.getUrl() then using that url you can view only file in browser if file will be image,video or pdf
0

It depends upon extension of the file you are trying to access via the url.

Extensions with img and mp4 can be easily viewed in a 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.

1 Comment

my primary focus is pdf, doc, & wps basically documents

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.