No send_data to send files as response


#1

Im generating a xls file using the gem axlsxand in Rails I use send_data method to send back the file as response but there is no related method on jets.

How to send back files?

Thanks!


#2

Jets currently does not support send_data method. Will consider a PR for this. However, this may be useful to know. There are some issues with sending binary data on API Gateway that limits the usefulness of send_data.

When I was playing with sending binary data via send_data, had some issues with things like images. Here’s a post with some details on this issue https://forums.aws.amazon.com/thread.jspa?threadID=243584

Essentially, some binary files do not get served correctly unless the client sends specific Accept headers. Examples:

Does not work:

curl URL -H 'Accept: image/webp,image/*, **/** ;q=0.8' https://api-gateway-dns/image.png # responds with base64 text while

Works:

curl URL -H 'Accept: image/webp' https://api-gateway-dns/image.png # responds with image correclty

This is important because with web browsers we don’t control the Accept header when the url is being hit directly. IE: An HTML img tag. So they don’t get served correctly.

At that point, I paused work on send_data and ended up serving binary data or assets out of s3 instead.

This is also a reason why files in the public folder are automatically uploaded to s3 and jets serves them out of s3 as part of the jets deploy process: Jets Assets Serving


#3

Thanks,

I changed my approach to send data to S3.

Thanks for your help!