I have a Rails app that lets a user upload an mp3 to their Profile model and then stores it with AWS S3. I am trying to figure out how to make a connection via Fog and stream their song when it's clicked, similar to the functionality of Soundcloud or Bandcamp. I have been looking at the Fog docs and similar posts, but am stuck. I think I have to use send_file, but am not sure. Any info would be greatly appreciated. I plan on using jplayer or something similar to actually play the audio, just need to make that connection happen on click.
UPDATE:
I am currently trying to implement something to this effect in my Profile controller, follwing this doc http://docs.aws.amazon.com/AWSRubySDK/latest/AWS/S3/Bucket.html
bucket = s3.buckets.create('name', :grants => {
:grant_read => [
{ :uri => "http://acs.amazonaws.com/groups/global/AllUsers" },
],
:grant_full_control => [
{ :id => 'abc...mno' } # cannonical user id
{ :email_address => 'foo@bar.com' }, # email address
]
})
In my view I have the following, just so I have something to look at and work with.
<audio id="song" class="audio_player" controls="false" preload="true">
<source src="/audios/ignite.mp3" type="audio/mpeg">
</audio>
So there is a disconnect here, kind of feel like I am taking shots in the dark. I think a little bit of clarity will put me on the right track. I have also unsuccessfully gotten Fog to work in my console, which would help things, but is a separate thread. Thank you for any help.
I suspect you won't actually want to stream the audio through your server. It would probably be better to just have the source attribute there point directly at s3. You have a couple options there. First, since you appear to have it set to public readability, you can just link directly to the url (I believe carrierwave has methods to give you this url). You could also do this without public read by using signed/expiring urls, but that gets a bit more complicated.
All that said, if it is really important that it appear to be coming from your server (instead of S3), you may want to look in to setting up a CNAME to S3 so that it is still being served from there, but will appear to come from a subdomain of your host (or similar). Hope that helps to point you in the right direction, but let me know otherwise and I can try to add further specificity. Thanks!