Any options for serving files from outside of public?

24 views
Skip to first unread message

French Fry

unread,
Oct 25, 2017, 6:27:45 PM10/25/17
to sinatrarb
I want to be able to play audio files that are outside root.  I've been reading around and it looks like options are non-existent.  Even if I set additional public folders, the files span multiples directories (and drives).  I looked at Rack::TryStatic but it looks like I'd have to downgrade Rack, from 2.x to 1.7.   Doesn't sound like a good idea. 

So I'm just throwing this out.  Maybe something I'm not aware of yet.  

Thanks
FF

Jason Rogers

unread,
Oct 25, 2017, 11:11:26 PM10/25/17
to sina...@googlegroups.com
The first argument to send_file can be an absolute or relative path. E.g.

get '/absolute' do
  send_file "/absolute/path/to/pic.jpg"disposition"inline"
end

get '/relative' do
  send_file "../../../relative/path/to/pic.jpg"disposition"inline"
end

Does that help?


--
Jason Rogers

--
You received this message because you are subscribed to the Google Groups "sinatrarb" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sinatrarb+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

French Fry

unread,
Oct 26, 2017, 1:50:16 PM10/26/17
to sinatrarb
Thank you for the reply Jason!  I hadn't noticed it till this morning.  Last night I played with send_file and while it "works" I ran into two problems.  The first might be fixable , that being, the send_file helper seems to take the header information from the file,  and insert it into the html audio component type option.  I did trying hard coding it into the helper options, but a) it didn't stick , while I tried using 'audio/mp3' , it reverts back to 'audio/mpeg'.  Still it works like that but nothing I could do with type audio/flac.  Just keeps going into octet stream and I get a download of the file. 

The second issue which is, I think, a side effect of the way send_file works is it just creates an html page with the player as the only component in the body.  I wanted the player as a partial , perhaps as a footer or something.  I haven't figured out if that is doable or not. 

Lastly, I was playing around with some javascript to preview files (onclick links, etc) but I think it still wouldn't work with the files outside of public. 


--
Jason Rogers

To unsubscribe from this group and stop receiving emails from it, send an email to sinatrarb+...@googlegroups.com.

French Fry

unread,
Oct 26, 2017, 3:49:21 PM10/26/17
to sinatrarb
Updating this post.  I am now able to get any file type/extension into the send file options.  Now I just need to figure out how to get the delivered inside a partial. 

Jason Rogers

unread,
Oct 26, 2017, 6:51:44 PM10/26/17
to sina...@googlegroups.com
Check out this gist: https://gist.github.com/jacaetevha/0c9b64c62d2fc30c05dd44f4090b5310

It's using Tilt and ERb, but you can use whatever rendering engines you want.


--
Jason Rogers

To unsubscribe from this group and stop receiving emails from it, send an email to sinatrarb+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages