simplecast-php icon indicating copy to clipboard operation
simplecast-php copied to clipboard

Direct Download URL

Open jrean opened this issue 9 years ago • 4 comments

Hi,

I guess this is not the convenient place to talk about this issue, but I would require the help of @mattstauffer and unfortunately I wasn't able to find your email...

I have a head scratching issue with Laravel 5 and SimpleCast. I have a /downloads/{id} route leading to a download controller action. Within that action I just want to return a "download" response to start the file download from the Direct Download Url provided by SimpleCast. Quite simple, on the front I have a download <a></a> button leading to that route. (I would like to have the same behaviour than Jeffrey has on Laracasts, videos are hosted on Vimeo, ..)

I'm up to date with the Laravel documentation and I did a lot of googling but I'm still stuck... I discovered return response()->download('http://audio.simplecast.fm/xxxx.mp3', 'filename.mp3'); is not working because download() is not working with remote files. Too bad!

How to achieve and perform the download? The file is not hosted on my server but on SimpleCast, I don't want to download the file on my server first... So! How would you manage it? I spent a couple of ours and I'm desperate because I'm not able at all to bring the download functionality... I guess I need to build a custom response() probably with custom headers and maybe with custom logic but... I'm stuck.

Would you please accept to help me. I will write a dedicated article on my blog (askjong.com) to share with the community.

Thank you in advance.

jrean avatar Jun 08 '15 14:06 jrean

@jrean Is there any reason you don't just point them directly to the mp3 file on simulcast's servers?

mattstauffer avatar Jun 08 '15 14:06 mattstauffer

@mattstauffer thank you :) First, when I directly open in my browser the Direct Download URL (mac chrome) it doesn't start downloading but instead redirect to a new page and start playing the podcast. http://audio.simplecast.fm/xxxx.mp3 redirects to: http://media.simplecast.fm/episodes/audio/xxxx/episode-title.mp3

Then if I simply add into my blade template the following code:

<a href="http://audio.simplecast.fm/xxxx.mp3">Test</a>

It doesn't start the download but instead redirects me to: http://media.simplecast.fm/episodes/audio/xxxx/episode-title.mp3

If I add the HTML5 property download to force the download it doesn't start the download neither

<a href="http://audio.simplecast.fm/xxxx.mp3" download>Test</a>

I like to play with things and I'm going crazy not to be able to manage that!

I try to tinker but I'm really really stuck!

        return response(readfile('http://audio.simplecast.fm/xxxx.mp3'), 200)
            ->header('Content-Type', 'audio/mpeg3')
            ->header('Content-Disposition', 'attachment; filename=download.mp3');

It displays characters and do not start the download neither...

I want to understand what I'm missing, and I want to achieve my first wish :)

jrean avatar Jun 08 '15 15:06 jrean

This is the simplecast's answer to my email:

We don’t have a way for you to force a Content-Disposition: attachment; header yet. You’ll have to tell people to right-click to download, or for HTML5 on certain browsers you can add the ‘download’ attribute to the link. http://davidwalsh.name/download-attribute

So now, I confirm I would like build my own streamed response. Jeffrey does it with Laracasts. You are a rockstar if you can help me. I already spent couple of hours and I don't want to drop the idea :)

jrean avatar Jun 08 '15 15:06 jrean

@jrean I think this is a super interesting idea, but as you can tell I don't have a ton of time to help out--sorry to be so un-accessible. I'll try to spend some time on it if I have any free time in the future, and let me know here if you end up solving it.

mattstauffer avatar Jun 30 '15 14:06 mattstauffer