T. S. Ferreira | 15 Nov 13:26

Problem with "Save Page As ..." after serve_file

I have a fairly complex application which uses the same method to
exhibit a choice page and then to exhibit a file which was requested,
using "cherrypy.lib.static.serve_file". It works fine except that when
I use the browser function "Save Page As ..." it saves not the
exhibited text file but the previous HTML choice page! There must be a
reason for this strange behavior but I could not figure it out :-(.

I prepared a small example (attached) which illustrates the problem.
It assumes that there are two additional text files "test1.txt" and
"test2.txt" in the directory in which the file "TestServer.py"
resides. I am using Python 2.5.1 and Cherrypy 3.1.0.

--

-- 
T. S. Ferreira

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "cherrypy-users" group.
To post to this group, send email to cherrypy-users@...
To unsubscribe from this group, send email to cherrypy-users+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/cherrypy-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Attachment (TestServer.py): application/octet-stream, 1402 bytes
Stefan J. Betz | 15 Nov 16:15

Re: Problem with "Save Page As ..." after serve_file

Am 2008-11-15 10:30:34 -0200, T. S. Ferreira schrieb:
> There must be a reason for this strange behavior but I could not
> figure it out :-(.

You are using HTTP POST Requests, and exactly here is your Problem. The
Browser does _not_ POST the same Request at the second Time ("Save Page
As... creates and Request!!!). When you are Using the HTTP GET Method it
works without any Problem.

Here is a Unified diff for your Problem:
--- TestServer.py	2008-11-15 16:12:05.000000000 +0100
+++ TestServer.py	2008-11-15 16:12:22.000000000 +0100
@@ -20,7 +20,7 @@
         flag = kwargs.get("flag",None)
         if flag==None:  # first time
             return """ <HTML><HEAD></HEAD><BODY>
-<FORM ENCTYPE="MULTIPART/FORM-DATA" ACTION="http://127.0.0.1:9999" METHOD="POST">
+<FORM ENCTYPE="MULTIPART/FORM-DATA" ACTION="http://127.0.0.1:9999" METHOD="GET">
 <INPUT TYPE=HIDDEN NAME=flag VALUE=on>
 <INPUT TYPE=RADIO NAME=choice VALUE=1 CHECKED> File 1<BR>
 <INPUT TYPE=RADIO NAME=choice VALUE=2 > File 2<P>

mfg Betz Stefan
--

-- 
Betz Stefan -- Webdesign & Computerservice
URL: http://www.stefan-betz.net
Mail: info@...
Tsf | 16 Nov 22:42

Re: Problem with "Save Page As ..." after serve_file


Thanks! Another solution for my application which requires downloading
is to use different arguments for serve_file:

    serve_file(file_path,"application/x-
download","attachment",file_name)

This seems to wrk with POST too.

-- Tsf

On Nov 15, 1:15 pm, "Stefan J. Betz" <stefan_b...@...> wrote:
> Am 2008-11-15 10:30:34 -0200, T. S. Ferreira schrieb:
>
> > There must be a reason for this strange behavior but I could not
> > figure it out :-(.
>
> You are using HTTP POST Requests, and exactly here is your Problem. The
> Browser does _not_ POST the same Request at the second Time ("Save Page
> As... creates and Request!!!). When you are Using the HTTP GET Method it
> works without any Problem.
>
> Here is a Unified diff for your Problem:
> --- TestServer.py       2008-11-15 16:12:05.000000000 +0100
> +++ TestServer.py       2008-11-15 16:12:22.000000000 +0100
> @@ -20,7 +20,7 @@
>          flag = kwargs.get("flag",None)
>          if flag==None:  # first time
>              return """ <HTML><HEAD></HEAD><BODY>
> -<FORM ENCTYPE="MULTIPART/FORM-DATA" ACTION="http://127.0.0.1:9999" METHOD="POST">
(Continue reading)

Robert Brewer | 16 Nov 23:13
Favicon
Gravatar

Re: Problem with "Save Page As ..." after serve_file


Tsf wrote:
> Thanks! Another solution for my application which requires downloading
> is to use different arguments for serve_file:
> 
>     serve_file(file_path,"application/x-
> download","attachment",file_name)
> 
> This seems to wrk with POST too.

It works so well, I stuck it into CherryPy 3.0's lib/static.py a couple
years ago:

def serve_download(path, name=None):
    """Serve 'path' as an application/x-download attachment."""
    # This is such a common idiom I felt it deserved its own wrapper.
    return serve_file(path, "application/x-download", "attachment",
name)

Robert Brewer
fumanchu@...

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "cherrypy-users" group.
To post to this group, send email to cherrypy-users@...
To unsubscribe from this group, send email to cherrypy-users+unsubscribe <at> googlegroups.com
For more options, visit this group at http://groups.google.com/group/cherrypy-users?hl=en
-~----------~----~----~----~------~----~------~--~---

(Continue reading)

Tsf | 19 Nov 01:43

Re: Problem with "Save Page As ..." after serve_file


I did not know it and wrote my own wrapper! Thanks.

-- tsf

On Nov 16, 8:13 pm, "Robert Brewer" <fuman...@...> wrote:
> Tsf wrote:
> > Thanks! Another solution for my application which requires downloading
> > is to use different arguments for serve_file:
>
> >     serve_file(file_path,"application/x-
> > download","attachment",file_name)
>
> > This seems to wrk with POST too.
>
> It works so well, I stuck it into CherryPy 3.0's lib/static.py a couple
> years ago:
>
> def serve_download(path, name=None):
>     """Serve 'path' as an application/x-download attachment."""
>     # This is such a common idiom I felt it deserved its own wrapper.
>     return serve_file(path, "application/x-download", "attachment",
> name)
>
> Robert Brewer
> fuman...@...
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "cherrypy-users" group.
To post to this group, send email to cherrypy-users@...
To unsubscribe from this group, send email to cherrypy-users+unsubscribe <at> googlegroups.com
(Continue reading)


Gmane