CGI to send back a file to save

Sivakatirswami katir at hindu.org
Mon Jul 18 22:46:08 EDT 2005


Aloha JB:

Yes, I did get this working with help from someone on Expert's  
Exchange.  But thank you... your note confirms the method... I use  
this for this context (sending a realAudio.ram file)

[SNIP]
put tURLStem & tMainFolder &"/" & tYear &"/" & tAudioFileName into  
tAbsoluteURL

# send this out to the browser as a file

put "Content-Type: audio/x-pn-realaudio" & cr
put "Content-Disposition: attachment; filename=real-player.ram" & cr  
& cr
put tAbsoluteURL

it works great... and opens some interesting doors for dynamic file  
delivery...

but I was told I didn't need a quote characater around the file name,  
didn't use it, and it seems to work just fine..

Regards
Sivakatirswami


On Jul 17, 2005, at 10:54 PM, jbv wrote:

> Hi,
>
> I'm a bit late on this thread, but I have some code that
> might help.
> What I actually do is generate on-the-fly pdf files with
> Rev cgi, and users get the usual WinXP dialog asking
> what they want to do with the file, save it or open it :
>
> put "Content-Type: application/pdf" & cr & "Content-Length : " &  
> number of chars of myPDF &
> cr & "Content-Disposition: attachment; filename=" &q& myRequestName  
> &q & cr & cr
>
> q contains the quote char.
>
> the above line works well under WinXP and MacOSX.
> I guess a few mods (in Content-Type mostly) may solve
> your problem...
>
> Best,
> JB
>
>
>
>> 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
>>
>> _______________________________________________
>> use-revolution mailing list
>> use-revolution at lists.runrev.com
>> Please visit this url to subscribe, unsubscribe and manage your  
>> subscription preferences:
>> http://lists.runrev.com/mailman/listinfo/use-revolution
>>
>
> _______________________________________________
> use-revolution mailing list
> use-revolution at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your  
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-revolution
>




More information about the use-livecode mailing list