📔
ServerlessDocs - Serverless File Service
  • Introduction
  • Why Serverless!!
  • Prerequisites
  • User Management
    • Authentication
    • Amazon Cognito
    • Create the User Pool
    • Create an App Client
    • Integrate the app with Cognito User Pool
    • Create the Identity Pool
    • Validate the setup
    • Troubleshooting
  • Manage Documents with AWS S3
    • Authorization
    • Update Cognito Identity Pool Auth Role
    • S3 Documents Bucket Folder Structure
    • Validate the Access Permissions
    • Public and Private files access
    • Upload Files to S3
    • Download Files
    • Delete Files
    • Share Files
  • More Security Configurations
    • Cognito user emails
    • Password policies
    • Allow only Organization and Whitelisted users to Signup
    • Allow admin users to upload Public files
    • Notify Admin users when a new user signup
    • Enable Multi-factor Authentication (MFA)
  • User Operations
    • Password Reset / Forgot Password
    • Resend Verification Code
  • Serverless APIs
    • APIs
    • Secure APIs using API Gateway Authorizer
    • Access Cognito values in Lambda function
    • Authorize APIs with OAuth 2 Scope
    • Fine-grained Access with AssumeRole
    • Notify Admin users on large file uploads
    • Generate a Month-To-Date Usage report
  • Source Code and Setup
    • Source Code
    • IAM Policies
    • S3 Bucket Policies
    • Suggestions / Feedback
    • More References
  • Deployment
    • AWS SAM
    • Serverless Framework
  • Contributors
    • Team
Powered by GitBook
On this page

Was this helpful?

  1. Manage Documents with AWS S3

Download Files

PreviousUpload Files to S3NextDelete Files

Last updated 4 years ago

Was this helpful?

Users can view/download files from the public folder or from their own folder.

I am using the simple Signed URL mechanism to download the file. This function will create the Signed URL and open that in the new tab.

function downloadFile(file){
    var s3 = new AWS.S3();
    var params = {Bucket: S3DocBucket, Key: file};
    var url = s3.getSignedUrl('getObject', params);
    window.open(url);
}

S3 pre-signed URL is an extremely useful feature. Here we are generating a pre-signed URL that will carry its own access token based on user's access token and that URL can be used to access the file.

Once we generate the pre-signed URL, we are using the URL in the next browser window for the download purpose.

We can use a pre-signed URL to securely upload objects to S3 without any direct access token or sign in required.

https://docs.aws.amazon.com/AmazonS3/latest/dev/PresignedUrlUploadObject.html