Search code examples
amazon-s3external

Upload File To AWS S3 with External Service


I need to upload video files from my frontend. You know that video files are large files so my backend resources might not be enough. To handle it, I am looking for external services. External service will upload the file to S3 and will authenticate it. Is there a service like that? Any suggestion?


Solution

  • Uploading via a proxy backend would be inefficient and would require advance file chunking upload mechanisms. To keep it simple, you will have to configure your backend APIs to:

    • Generate a pre-signed URL that will reserve an object slot on your S3 bucket using AWS SDK for your programming language of choice.
    • Consider adding an expiry so that uploading against would only be available for a limited period of time. (This reduces the window for hijacked pre-signed URL attacks)
    • You will have to grant PutObject policy to your backend's compute IAM role. Without this, you'll get unauthorized upload errors.
    • Once you get hold of your pre-signed URL in the backend layer, you could send back a response to your client-side application.
    • This pre-signed URL could then be used in the client-side code to directly upload huge files from the browser to S3 bucket without overwhelming your application's API layer. Consider using S3's multipart upload and transfer acceleration to speed up the transfer between your client and the S3 buckets. Check out this article to learn more.