Skip to content
Advertisement

Return S3 private file as stream

I’m currently working on a route for a project that I need to get a specific file from S3, read its content, and return as a binary. I can’t just use the S3 file url, because it is private and it is intentional (we just don’t want the bucket files open).
But the problem is, I want to stream it in a new page to not have the need to download the file.
Service:

JavaScript

Controller:

JavaScript

Advertisement

Answer

I thought you are using Laravel, if so then you could return your image like this:

JavaScript

Another way that I use to return image is:

JavaScript

Content-Type should be your image type (JPG, PNG, etc.).

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement