I want to return multiple image files at the same time in Rails response

Asked 1 years ago, Updated 1 years ago, 90 views

I am currently developing mobile apps using Rails and ReactNative.

I would like to send multiple images downloaded from s3 directly to the client.

The image uploaded from the client is saved in S3, and when I return the saved image to the client, I return s3's signed_url to read and display it on the client side.

What are the problems with your current implementation

By passing the presigned_url to the client, the client must send a request to the presigned_url again to retrieve the image after receiving a response from the Rails server.
With this method, it takes a lot of time to complete loading when you want to get about 10 images together.

Based on the above points, I would like to download the file from s3 on the Rails server and send the file directly from the Rails server to the client (at the same time).

I looked at the send_file document and found no way to send multiple images, so please let me know if you know any good way.

ruby-on-rails amazon-s3 react-native

2022-09-30 11:33

1 Answers

Preface

Do you mean that you want to get all 10 images with one HTTP GET?
In that case, unless "Rails Server to Client" is clearly faster than "S3 to Client", it will not change much.

(Basically, the response of GET cannot be displayed until all the responses of GET are read, so the response size from the Rails server increases, so users may feel slower.)

If S3 is slow to respond, please consider CDN such as CloudFront.

Title

Extremely speaking, the file format returned by GET is optional on the server, so you can return it in any binary format as long as the client can recognize it.

Generally, when multiple files are returned from the server, I think a container format such as zip will be adopted.I think you can create the original container format (for example, just a binary with image binaries) and return it.


2022-09-30 11:33

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.