Nuby
Nuby

Reputation: 2386

Sending a File Already in Memory

So I am pulling some data and processing it from a third-party API. After some re-formatting, I end up with a file in memory. I know that I can write that file to disk and then send_file or render it to the user for download by referencing the file name. However, is there a way to just render the file itself (since it's already loaded into memory)?

Every method I've seen has involved passing a filename, but this file only exists in memory and I'd rather not write to temp and then read back. I figured I need to render the right type of text and change the content_type, but I haven't found the right mix. Any advice?

Upvotes: 2

Views: 227

Answers (1)

sled
sled

Reputation: 14635

send_data is what you need (the filename option is the "name of the download") ActionController::Streaming

Upvotes: 3

Related Questions