CGI to send back a file to save
Sivakatirswami
katir at hindu.org
Tue Jul 12 23:00:09 EDT 2005
Short version: I need to know the proper HTTP header to set to force
a browser to save the incoming data to a file. (at least I *think*
that's what I need to know.)
Long Scenario:
Goal: create a CGI that responds to a GET request that will
automatically generate a
fooSoundFile.ram "file in a variable"
based on the query string e.g.
$QUERY_STRING = audioFile=hawaii_papayas.mp3
then the .ram filename should be "hawaii_papayas.ram"
and contain the string:
"http://www.himalayanacademy.com/audio/tropical_fruit_music/
hawaii_papayas.mp3"
[you should hear those papayas sing!]
Now, generating all that is a easy enough.
But the usual scenario is that you have all these .ram files prebuilt
(which is what I am trying to avoid. Old .ram files lying around the
web site are a *big* nuisance to maintain....) and the user clicks on
a link
<a href="/audio/tropical_fruit_music/hawaii_papayas.ram">Real Player</a>
and the .ram file is downloaded-saved to the client side disk... Real
Player is mapped to .ram in the internet helper apps, boots and reads
this file and streams the audio.
I want the CGI to take over that process and serve the .ram file
dynamically.
OK, so all I know how to do is:
put "http://www.himalayanacademy.com/audio/tropical_fruit_music/
hawaii_papayas.mp3" into tRamFile
http://www.himalayanacademy.com/audio/tropical_fruit_music/
hawaii_papayas.mp3
put "Content-Type: text/plain" & cr
put "Content-Length:" && the length of tRamFile & cr & cr
put tRamFile
of course this is not going to work... that string will appear as a
literal in the user's browser. is it as simple as something like:
# just guessing.. I haven't a clue...
put "Content-Type: binary/file" & cr
put "Content-Length:" && the length of tRamFile & cr & cr
put tRamFile
# where the browser can't read it, so it saves it
??
i.e. we can of course do a redirect, like this:
put
"http://www.himalayanacademy.com/audio/tropical_fruit_music/
hawaii_papayas.mp3" into tRamFile
put tRamFile into url ("file:" & "audio/tropical_fruit_music/
hawaii_papayas.ram")
put "Status: 301 Moved Permanently" & cr
put "Location: " & http://www.himalayanacademy.com/audio/
tropical_fruit_music/hawaii_papayas.ram" & cr & cr
But, then I end up once again, with all these .ram files on disk...
so I was hoping to find a way to pipe it straight out of the CGI...
i.e. to take what is coming back from port 80 and save it instead of
trying to render it...maybe this is the wrong place to ask this... I
will take it to Experts-Exchange if no one here knows.
TIA
Sivakatirswami
More information about the use-livecode
mailing list