NetTalk Central

Author Topic: How do I make a download link that will save the file  (Read 9399 times)

Big Ian

  • Newbie
  • *
  • Posts: 31
  • I wonder what happens if I press this button
    • MSN Messenger - ian.holdsworth@gmail.com
    • View Profile
    • Email
How do I make a download link that will save the file
« on: January 17, 2008, 03:21:47 AM »
Hi All

Newbie question

How do I make a download link that will save the file rather than display it in the browser?

Cheers
Ian Holdsworth
Ram Ltd

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11179
    • View Profile
Re: How do I make a download link that will save the file
« Reply #1 on: January 22, 2008, 03:42:08 AM »
Hi Ian,

In one sense it's not up to you. The browser is ultimately responsible for deciding what to do with the files it fetches.

But fortunately there is a way to convince it that it "doesn't know what to do with this file".
The trick is in the Content-Type that is sent back with the file. Basically this is something that tells the browse what sort of file it is receiving. If you set this to something completely unknown then the browser will throw up its arms and ask the user to save the file.

You can set the content type like this
p_web.ReplyContentType = 'bruce/whatever'

_Where_ you set it depends a bit on what kind of "page" you're sending, ie if it's a static or dynamic page. Typically you'd set it in webhandler._sendfile method, before the parent call, but of course _only_ if the page being sent is the page in  question. (There's a parameter to sendfile that'll help you figure this out.)

Cheers
Bruce




Big Ian

  • Newbie
  • *
  • Posts: 31
  • I wonder what happens if I press this button
    • MSN Messenger - ian.holdsworth@gmail.com
    • View Profile
    • Email
Re: How do I make a download link that will save the file
« Reply #2 on: January 23, 2008, 04:40:22 AM »
Thanks Bruce
Ian Holdsworth
Ram Ltd

Big Ian

  • Newbie
  • *
  • Posts: 31
  • I wonder what happens if I press this button
    • MSN Messenger - ian.holdsworth@gmail.com
    • View Profile
    • Email
Re: How do I make a download link that will save the file
« Reply #3 on: January 23, 2008, 06:26:55 AM »
BTW I can't help but feel I'm missing a trick here but is there a manual for all the P_WEB methods & properties?

I've searched and searched and can't seem to find one.

Cheers
Ian Holdsworth
Ram Ltd

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11179
    • View Profile
Re: How do I make a download link that will save the file
« Reply #4 on: January 24, 2008, 10:49:27 PM »
Hi Big Ian,

Alas, no not yet. The properties and methods are not quite finished yet, so the technical docs for them hasn't started yet.

However the list of them is in \clarion\libsrc\netweb.inc and the code is in \clarion\libsrc\netweb.clw.

And of course if you have any questions feel free to ask.

Cheers
Bruce

Big Ian

  • Newbie
  • *
  • Posts: 31
  • I wonder what happens if I press this button
    • MSN Messenger - ian.holdsworth@gmail.com
    • View Profile
    • Email
Re: How do I make a download link that will save the file
« Reply #5 on: February 29, 2008, 04:33:30 AM »
Bruce

Sorry about this I only just got to try it out.  I'm sending my file and setting the content type as below

    self.ReplyContentType = 'application/zip'

in the webhandler before the parent call for _Sendfile however the file is still being displayed in the browser see below

HTTP/1.0 200 OK Date: Fri, 29 Feb 2008 12:26:26 GMT Server: NetTalk-WebServer/4.23 Beta ETag: "75659:6207201" Expires: Thu, 01 Mar 2007 12:26:26 GMT Last-Modified: Wed, 20 Feb 2008 17:14:32 GMT Content-Type: text/html Cache-Control: no-store, no-cache, must-revalidate, private,post-check=0, pre-check=0, max-age=0 Connection: close PK���ωT8HÈkÕ9�>Ž� ���OUT00002.csv´][s›È¶~?Uç?tÍs¢¡¹sž„�ÝŒ.dÅSS5Õ–ÚÛ\€¢ñþõ§/€dDZåÊÊdbc[±øºW¯õ­+ÔiÑ?¾ü‘æi’¬b—Õ¡ÌÉž“l·%­*|ºTO—ÚéRg—OEUoŠ-ÿgÁ̝„ìsDïÙÇá¡>”Ô+òšljþë7$ß’š¿°NïïÓ=yà׿ôÿÿþϳ’]̦ìC¼OëãŒÔÈú‚ÆéÃî>¥ÙÍH^”Í7Ø ’约ùŽä”ÿã¸î!7»#9_„1-ëû¢ÜV»´ä·ç†ºâÎù[¸ßÖAþÏ&ɸ?H&ó$ˆæAÒó3öcMÑ›¯­êü©˜ªŠb!Eù?Eaßúûo·z¢ùß×ZÕi‘ç„ý~ä–›]úþ])–b}ÝYº%Ï+ì?ǽd2„Z¡ˆã&e–æìÊBÉŽ¢[šˆnê¢|F#Rn©XõŽ’zGöOUMÉö‚õ±]Ÿ¿ÁbÞOÜ(œÌGlIz«+±(†n:ìâ–/Šýë‹bclQ8š%_&öB4-È£”˜¨Ð9`R²[dkó&xCóßáΙ$$A¿ù<

Any Ideas?
Ian Holdsworth
Ram Ltd

Rob Mikkelsen

  • Full Member
  • ***
  • Posts: 107
    • Yahoo Instant Messenger - flashpott
    • View Profile
    • Email
Re: How do I make a download link that will save the file
« Reply #6 on: February 29, 2008, 07:04:48 PM »
In the routine that creates the file, I send something like this after the file is created:

    Packet='<br><button type="button" name="Download" id="Download" value="Download" onclick="window.open(''' & 'download/' & CLIP(Loc:WebFolder) & '/' & CLIP(Loc:FileName) & ''',''_self'')">Download ' & CLIP(Loc:Description) & '</button>'
    Packet=CLIP(Packet) & '</br>'
DO Sendpacket



I isolate the files by session number, so the path is web\download\sessionnumber\filename.ext.  I do this to keep common names, and allow a person to see what files he/she created via a browse.

I also have a cleanup routine that deletes everything in the web\download folder (and subfolder) after two hours.

To ensure that the file is sent correctly, I add the following code in the WebHandler, ThisNetWorker._SendFile, before parent call

! unless otherwise specified, make the reply content type unknown to force download   
    IF Instring('download',LOWER(p_FileName),1,1) THEN
      self.ReplyContentType='countops/download'
    END
   
! force download of TTP files regardless of the location   
    IF Instring('.ttp',LOWER(p_FileName),1,1) THEN
      self.ReplyContentType='countops/ttp'
    END
   
! allow display of .csv files regardless of the location   
    IF Instring('.csv',LOWER(p_FileName),1,1) THEN
      self.ReplyContentType='application/vnd.ms-excel'
    END

   
 When the user clicks on the button, the file is either displayed in the current window (it can be moved to a separate window by changing the _self to something else, or the download dialog box opens.  Pretty cool.    


Big Ian

  • Newbie
  • *
  • Posts: 31
  • I wonder what happens if I press this button
    • MSN Messenger - ian.holdsworth@gmail.com
    • View Profile
    • Email
Re: How do I make a download link that will save the file
« Reply #7 on: March 03, 2008, 04:12:20 AM »
flashpot

It would be cool if it worked however it is still loading the zip file straight into the web page and is not giving me the option to download it whatever I set the content type to.  This is really getting frustrating!

Thanks for the help mate but I think I can see myself writing an ftp server to get around this.

Cheers
Ian Holdsworth
Ram Ltd

Rob Mikkelsen

  • Full Member
  • ***
  • Posts: 107
    • Yahoo Instant Messenger - flashpott
    • View Profile
    • Email
Re: How do I make a download link that will save the file
« Reply #8 on: March 03, 2008, 06:07:18 AM »
Big Ian,

I had the EXACT same problem that you did when I tried using the p_Web._SendFile routine, but when I put it on a button and called it as a separate entity it worked just fine.  I figured it was because the inline call had already resolved the file type when it started loading the HTML page and just treated the file as inserted HTML. 

I have used this technique with a number of different files and have had great success with it.

I am sure there is a simple workaroud for this.  Don't give up hope!

Rob

Big Ian

  • Newbie
  • *
  • Posts: 31
  • I wonder what happens if I press this button
    • MSN Messenger - ian.holdsworth@gmail.com
    • View Profile
    • Email
Re: How do I make a download link that will save the file
« Reply #9 on: March 04, 2008, 04:11:25 AM »
dldldldldldldl tisch

Got it working!!!!!!!!  All I'd missed was on the netweb page settings changing the type to other.    Now all I need is to change the default name of the file to something other than my procedure name which I suspect is not easy.

Thanks for all your help

Big Ian
Ian Holdsworth
Ram Ltd

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11179
    • View Profile
Re: How do I make a download link that will save the file
« Reply #10 on: March 04, 2008, 07:30:18 AM »
Hi Ian,

Sorry for the delay, I've been a tad busy.

The bit you were missing was to set the content type _before_ the header was sent. Changing the netWebPage to other helped you do this.

Regarding the name - yes it will be difficult. The name it suggests is the name it "asked for". In order to get a different default name, it needs a different URL. That said you could add hand-code to the WebHandler procedure to "redirect" any number of names to your NetWebPage procedure.

Cheers
Bruce