mr_muscle
mr_muscle

Reputation: 2900

Rails downloads PDF instead of displaying it

In my Rails app I'm using Faraday to connect with 3rd party API. In one of the endpoint I'm downloading the pdf which means that the API will send me a binary file as a response. Now I want to display this pdf to the user, to make it work I've got below controller action:

def document
  file = client.document(params[:id])

  send_data(file, disposition: 'inline', type: 'application/pdf')
end

But instead of displaying the PDF, the download is started. What did I missed?

Upvotes: 0

Views: 198

Answers (1)

mr_muscle
mr_muscle

Reputation: 2900

Found the solution, maybe it will be helpful for someone in the future.

All I need was to set Content-Disposition headers like below:

def document
  file = client.document(params[:id])

  send_data(file, disposition: 'inline', type: 'application/pdf', headers: { 'Content-Disposition' => 'inline' })
end

Upvotes: 1

Related Questions