Reputation: 1287
I cant figure out what Im doing wrong here. Im using Carrierwave to allow users to upload PDF files to AWS. So far upload and record creation go off without a hitch and when browsing the S3 bucket Im able to download and read the file no problem.
The issue Im having is with the "send_data" function in my controller The file download is being triggered, but instead of the PDF thats in AWS im getting a txt file(with PDF extension), that contains only the path to the file.
here is my code, hopefully more experienced eyes will spot my error.
send_data @document.file.url.to_s, :type => "application/pdf", :disposition => "attachment", :filename => @document.title.to_s
Upvotes: 3
Views: 1657
Reputation: 44370
Look at semantic for those methods:
send_data(data, options = {})
send_file(path, options = {})
For send_data()
you should open and read the file, for send_file()
you can use just a path to file.
send_data(File.read(@document.file.url.to_s), type: "application/pdf", disposition: "attachment", filename: @document.title.to_s)
Upvotes: 4