I have been doing rails application that used carrierwave for file uploads. How can I send existing file to a client using Grape API? Let's assume that file is in directory "public/uploads/datafile/1/file.txt".
I was getting utf8 character conversion if i didn't set 'api_format'
if file_path && File.exists?(file_path)
data = File.open(file_path, 'rb').read
header "Content-Disposition:", " infile; filename=\"#{File.basename(file_path)}\""
content_type 'application/x-gzip'
env['api.format'] = :binary
present data
end
This was on grape 0.4.1
As long as you set the content type, it's as easy as sending the contents of the file.
content_type "text/plain"
File.read(...)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With