Home Forum NetTalk Wiki Download/Upload Links Search Fat Chat
Links

Clarion

Clarion Desktop
Capesoft

Java Script

Java Calendar

NetTalk WebServers

POSitive Connect

Clarion Sites

Pimp my Clarion

RSS Feeds

Add to MyYahoo!
Subscribe in NewsGator Online
Add to Newsburst
Add to Google
Add to My AOL
Add to Pluck
Subscribe in FeedLounge
Add to Windows Live
Add to NetVibes
Subscribe in Rojo
Subscribe in Bloglines
Add to MyMSN
Add to Plusmo for your cellphone
Add to PageFlakes
Add to Technorati
Add to BlinkBits

Site Stats

Visits today: 169
Visits yesterday: 163
Visits month: 4737
Visits total: 114621
Max.monthly visits: 4941
  occurred: 2010-6
Pages this month: 24078
Pages total: 646018
Data since: 2007-06-23
Home arrow Forum arrow NetTalk Web Serverarrow Web Server - Ask For Helparrow How do I make a download link that will save the file
NetTalk Central
July 30, 2010, 03:50:54 pm *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Welcome to the NetTalk Central Forums!
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: How do I make a download link that will save the file  (Read 2052 times)
Big Ian
Newbie
*
Posts: 31


I wonder what happens if I press this button

ian.holdsworth@gmail.com
View Profile Email
« 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
Logged

Ian Holdsworth
Ram Ltd
Bruce
Hero Member
*****
Posts: 1733



View Profile
« 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



Logged
Big Ian
Newbie
*
Posts: 31


I wonder what happens if I press this button

ian.holdsworth@gmail.com
View Profile Email
« Reply #2 on: January 23, 2008, 04:40:22 am »

Thanks Bruce
Logged

Ian Holdsworth
Ram Ltd
Big Ian
Newbie
*
Posts: 31


I wonder what happens if I press this button

ian.holdsworth@gmail.com
View Profile Email
« 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
Logged

Ian Holdsworth
Ram Ltd
Bruce
Hero Member
*****
Posts: 1733



View Profile
« 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
Logged
Big Ian
Newbie
*
Posts: 31


I wonder what happens if I press this button

ian.holdsworth@gmail.com
View Profile Email
« 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���ωT8Hk9�>� ���OUT00002.csv][sȶ~?U?tss�݌.dSS5Ֆ\/dDZdbc[W+i?ibաɞl%*|TORgOEUo-g̝sD>+lj7$ߒN=y׿]̦CO>H^7 约!7#9_1-V熺[A&ɸ?H&$A3cMb!E?EaozZi~䖛]])b}Y%+?d2Z&eBɎ[n|F#RnXzGOUM]bO(GlIz+(n:/bclQ8%_&B4-ȣ9`R[dk&xCΙ$$A<

Any Ideas?
Logged

Ian Holdsworth
Ram Ltd
flashpot
Jr. Member
**
Posts: 89

flashpott
View Profile Email
« 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.    

Logged
Big Ian
Newbie
*
Posts: 31


I wonder what happens if I press this button

ian.holdsworth@gmail.com
View Profile Email
« 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
Logged

Ian Holdsworth
Ram Ltd
flashpot
Jr. Member
**
Posts: 89

flashpott
View Profile Email
« 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
Logged
Big Ian
Newbie
*
Posts: 31


I wonder what happens if I press this button

ian.holdsworth@gmail.com
View Profile Email
« 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
Logged

Ian Holdsworth
Ram Ltd
Bruce
Hero Member
*****
Posts: 1733



View Profile
« 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

Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC
Joomla Bridge by JoomlaHacks.com
Valid XHTML 1.0! Valid CSS!

Login Form

Welcome Guest.






Lost Password?
No account yet? Register

ClarionMag News

mod_dbrss2 AJAX RSS Reader poweredbysimplepie
home contact search contact search