I've got call recordings stored on a CDN (Rackspace CloudFiles) with names like:
KPOWIEJFIE2034020SVN10ASKZALBMRI.mp3
(They're Twilio Call SIDs).
My application (CakePHP) displays a list of these recordings, and uses an <audio>
tag to allow them to be played on the page right from the CDN. I need to add the option to download the file directly as well, but I want to download the file named something more like this:
Call from Alex to Firm, Inc, 8/19/2011 4:00pm.mp3
I know how to do this with PHP and readfile() to set the name to whatever I'd like, but that requires the file data be streamed through my VPS. Besides being billed twice for the bandwidth (once through the CDN and once through my VPS), this would defeat the purpose of having my files on a CDN (speed and availability). I have the files named only with the call SID on the CDN for security.
Can I do this with browser-side somehow? Can JavaScript change the name of a downloaded file on the fly?
I appreciate any help!
I've got call recordings stored on a CDN (Rackspace CloudFiles) with names like:
KPOWIEJFIE2034020SVN10ASKZALBMRI.mp3
(They're Twilio Call SIDs).
My application (CakePHP) displays a list of these recordings, and uses an <audio>
tag to allow them to be played on the page right from the CDN. I need to add the option to download the file directly as well, but I want to download the file named something more like this:
Call from Alex to Firm, Inc, 8/19/2011 4:00pm.mp3
I know how to do this with PHP and readfile() to set the name to whatever I'd like, but that requires the file data be streamed through my VPS. Besides being billed twice for the bandwidth (once through the CDN and once through my VPS), this would defeat the purpose of having my files on a CDN (speed and availability). I have the files named only with the call SID on the CDN for security.
Can I do this with browser-side somehow? Can JavaScript change the name of a downloaded file on the fly?
I appreciate any help!
Share Improve this question asked Aug 19, 2011 at 14:57 Alex FordAlex Ford 2331 gold badge3 silver badges8 bronze badges 2-
You'd have to somehow change the
Content-disposition:
header that's sent to the user's browser. That header can be used to set things like the file name and creation date. I'm not sure how you'd modify the headers that way, but you could save some bandwidth by caching the recording on your server so that you're only charged for double bandwidth once. – Adam Fabicki Commented Aug 19, 2011 at 15:02 - forums.aws.amazon./thread.jspa?threadID=44958&tstart=0 -- That may help, I'm not sure what you can do on Rackspace – Joe Simpson Commented Aug 19, 2011 at 15:05
3 Answers
Reset to default 2The filename is based on the URL being requested and the headers attached to the response when the URL is fetched. Unless you proxy it, or can arrange for a "friendly" url to point at the resource, you have no control over how the browser will download the file, since the request will be handled by the rackspace servers, not your code.
JS cannot control the fetch/download process, other than possibly mangling the url that goes into the <audio>
tag. but then you're limited to whatever mangling still allows the URL to be relevant to the cloudfiles servers.
You should be able to set an object's Content-Disposition when creating the file. For example,
PUT /<api version>/<account>/<container>/<object> HTTP/1.1
Host: storage.clouddrive.
X-Auth-Token: 01234567-89ab-cdef-0123-456789abcdef
Content-Type: audio/mpeg
Content-Disposition: attachment; filename=Whatever_Filename_I_Want.mp3
The file will still be stored as whatever your <object>
name is, but when retrieved it will appear as Whatever_Filename_I_Want.mp3
.
Edit: According to the documentation, you can also update a file's metadata using this method.
From what I understand of the documentation, you're able to build a directory structure on the CDN for your purposes. So instead of relying on the security with the filename, you could put the security into the directory name. That way, http://cdn.example./KPOWIEJFIE2034020SVN10ASKZALBMRI.mp3
bees http://cdn.example./KPOWIEJFIE2034020SVN10ASKZALBMRI/Call_from_Alex_to_Firm,_Inc,_8-19-2011_4:00pm.mp3
, which will download exactly as you want it to be, without sacrificing the security.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744181375a4561997.html
评论列表(0条)