Hi, I am a newbie of nevow. I want to open a save as dialog and enable the user to save files. I tried to use javascript with a href link but with no success. I write: """ ... file = open('fifo.txt', 'w') file.write('smth') file.close() return [ T.a(href="fifo.txt", onclick="saveFile('fifo.txt')")['Save'], webform.renderForms()[FORM_LAYOUT], ] """ How can I achieve in this? How can I give a link to a file in the server without nevow_carryover repling the request? Suha
On 04:31 pm, suhaonay@gmail.com wrote:
I am a newbie of nevow. I want to open a save as dialog and enable the user to save files.
Are you talking about uploading a file to the server, or saving a file on the client? (You can't save files on the client in a web browser in any way that I'm aware of.)
On Tue, 11 Mar 2008 13:37:08 -0500, <glyph@divmod.com> wrote:
On 04:31 pm, suhaonay@gmail.com wrote:
I am a newbie of nevow. I want to open a save as dialog and enable the user to save files.
Are you talking about uploading a file to the server, or saving a file on the client? (You can't save files on the client in a web browser in any way that I'm aware of.)
I think the OP is talking about providing a link to some downloadable content, e.g., a spreadsheet or an image, that should trigger the browser's download behavior. Then again, I could be wrong. L. Daniel Burr
Yes Daniel is right. Sorry about the wrong question. I am talking about providing a link to some downloadable content, e.g., a spreadsheet or an image. How is it possible in nevow? On Tue, Mar 11, 2008 at 8:51 PM, L. Daniel Burr <ldanielburr@mac.com> wrote:
On Tue, 11 Mar 2008 13:37:08 -0500, <glyph@divmod.com> wrote:
On 04:31 pm, suhaonay@gmail.com wrote:
I am a newbie of nevow. I want to open a save as dialog and enable the user to save files.
Are you talking about uploading a file to the server, or saving a file on the client? (You can't save files on the client in a web browser in any way that I'm aware of.)
I think the OP is talking about providing a link to some downloadable content, e.g., a spreadsheet or an image, that should trigger the browser's download behavior.
Then again, I could be wrong.
L. Daniel Burr
_______________________________________________ Twisted-web mailing list Twisted-web@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web
-- Suha ONAY Likya Yazılım ve Bilişim Hizmetleri Ltd.Şti. Galyum Blok No: B-08 ODTÜ Teknokent 06531 Ankara - Türkiye Tel :: (312) 210 00 90 Fax :: (312) 210 00 91 Web :: www.ly.com.tr
On Wed, 12 Mar 2008 08:55:37 +0200 "Suha Onay" <suha@ly.com.tr> wrote:
Yes Daniel is right. Sorry about the wrong question. I am talking about providing a link to some downloadable content, e.g., a spreadsheet or an image. How is it possible in nevow?
On Tue, Mar 11, 2008 at 8:51 PM, L. Daniel Burr <ldanielburr@mac.com> wrote:
On Tue, 11 Mar 2008 13:37:08 -0500, <glyph@divmod.com> wrote:
On 04:31 pm, suhaonay@gmail.com wrote:
I am a newbie of nevow. I want to open a save as dialog and enable the user to save files.
Are you talking about uploading a file to the server, or saving a file on the client? (You can't save files on the client in a web browser in any way that I'm aware of.)
I think the OP is talking about providing a link to some downloadable content, e.g., a spreadsheet or an image, that should trigger the browser's download behavior.
You should use nevow.static.File, a quick example (save in example.tac and run with "twistd -noy example.tac"): from nevow import static, appserver from twisted.application import service, internet, strports application = service.Application("example") site = appserver.NevowSite( resource=staic.File("thing.jpeg", "image/jpeg")) server = strports.service("tcp:8080", site) server.setServiceParent(application) You can construct a nevow.static.File passing a path to a directory, and you will be serving all the contents of the directory. Cheers, -- ~ ~ ~ ".signature" 4 lines, 50 characters written
In the base page, I served the xxx directory for static files with the following lines. def child_xxx(self, ctx): return static.File(os.path.join(LQS.WEB_SERVER, 'xxx')) On the page that will serve a link to the file, the file is saved to the xxx directory and a link is given: f= open(os.path.join(LQS.WEB_SERVER, 'xxx', 'qqq.lqp'), 'w') f.write(fileInput) f.close() return [ T.a(href="/xxx/qqq.lqp")['Save'], webform.renderForms()[FORM_LAYOUT], ] I run this page from Firefox, IE and IE Mobile. I want the browser open a save as dialog but it shows the file within the browser. How can I achieve this? Thanks. On Wed, Mar 12, 2008 at 7:16 PM, Adrian Perez <moebius.lists@gmail.com> wrote:
On Wed, 12 Mar 2008 08:55:37 +0200 "Suha Onay" <suha@ly.com.tr> wrote:
Yes Daniel is right. Sorry about the wrong question. I am talking about providing a link to some downloadable content, e.g., a spreadsheet or an image. How is it possible in nevow?
On Tue, Mar 11, 2008 at 8:51 PM, L. Daniel Burr <ldanielburr@mac.com> wrote:
On Tue, 11 Mar 2008 13:37:08 -0500, <glyph@divmod.com> wrote:
On 04:31 pm, suhaonay@gmail.com wrote:
I am a newbie of nevow. I want to open a save as dialog and enable the user to save files.
Are you talking about uploading a file to the server, or saving a file on the client? (You can't save files on the client in a web browser in any way that I'm aware of.)
I think the OP is talking about providing a link to some downloadable content, e.g., a spreadsheet or an image, that should trigger the browser's download behavior.
You should use nevow.static.File, a quick example (save in example.tac and run with "twistd -noy example.tac"):
from nevow import static, appserver from twisted.application import service, internet, strports
application = service.Application("example") site = appserver.NevowSite( resource=staic.File("thing.jpeg", "image/jpeg")) server = strports.service("tcp:8080", site) server.setServiceParent(application)
You can construct a nevow.static.File passing a path to a directory, and you will be serving all the contents of the directory.
Cheers,
-- ~ ~ ~ ".signature" 4 lines, 50 characters written
_______________________________________________ Twisted-web mailing list Twisted-web@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web
-- Suha ONAY Likya Yazılım ve Bilişim Hizmetleri Ltd.Şti. Galyum Blok No: B-08 ODTÜ Teknokent 06531 Ankara - Türkiye Tel :: (312) 210 00 90 Fax :: (312) 210 00 91 Web :: www.ly.com.tr
On 13/03/2008 09:16 Suha Onay wrote:
return [ T.a(href="/xxx/qqq.lqp")['Save'], webform.renderForms()[FORM_LAYOUT], ]
I run this page from Firefox, IE and IE Mobile. I want the browser open a save as dialog but it shows the file within the browser. How can I achieve this?
You need to set the MIME type for that extension. Not sure how to do this with the static file method, there is a mapping somewhere which you can pass as arguments to the instance if I remember correctly.
On Thursday 13 March 2008, Suha Onay wrote:
I run this page from Firefox, IE and IE Mobile. I want the browser open a save as dialog but it shows the file within the browser. How can I achieve this?
You can set the following HTTP header: Content-Disposition: attachment; filename Where "filename" is the suggested name for saving the file. Note that HTTP headers must be ASCII. It is possible to encode Unicode in HTTP headers, but it's a real pain to get it working in all browsers. At least, I haven't been able to find a single way of encoding that works for IE, Mozilla and Opera, so now I choose a different way of encoding depending on the user agent header. Bye, Maarten
How is it possible to set the HTTP header of the link to this file (qqq.lqp )? f= open(os.path.join(LQS.WEB_SERVER, 'xxx', 'qqq.lqp'), 'w') f.write(fileInput) f.close() return [ T.a(href="/xxx/qqq.lqp")['Save'], webform.renderForms()[FORM_LAYOUT], ] On Thu, Mar 13, 2008 at 3:23 PM, Maarten ter Huurne <maarten@treewalker.org> wrote:
On Thursday 13 March 2008, Suha Onay wrote:
I run this page from Firefox, IE and IE Mobile. I want the browser open a save as dialog but it shows the file within the browser. How can I achieve this?
You can set the following HTTP header: Content-Disposition: attachment; filename Where "filename" is the suggested name for saving the file.
Note that HTTP headers must be ASCII. It is possible to encode Unicode in HTTP headers, but it's a real pain to get it working in all browsers. At least, I haven't been able to find a single way of encoding that works for IE, Mozilla and Opera, so now I choose a different way of encoding depending on the user agent header.
Bye, Maarten
_______________________________________________ Twisted-web mailing list Twisted-web@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web
-- Suha ONAY Likya Yazılım ve Bilişim Hizmetleri Ltd.Şti. Galyum Blok No: B-08 ODTÜ Teknokent 06531 Ankara - Türkiye Tel :: (312) 210 00 90 Fax :: (312) 210 00 91 Web :: www.ly.com.tr
On Thursday 13 March 2008, Suha Onay wrote:
How is it possible to set the HTTP header of the link to this file (qqq.lqp )?
f= open(os.path.join(LQS.WEB_SERVER, 'xxx', 'qqq.lqp'), 'w') f.write(fileInput) f.close()
return [ T.a(href="/xxx/qqq.lqp")['Save'], webform.renderForms()[FORM_LAYOUT], ]
The HTTP header cannot be set on the link; the header should be set when serving the file download. This is just a matter of calling setHeader() on the request. I'm not very familiar with Nevow, so I don't know where that call should be placed. By the way, instead of generating a file on the server and offering that for download, it might be simpler to send the data directly to the client. That way you don't have to worry about uniqueness of file names, cleaning up files when they are no longer needed etc. Bye, Maarten
On Thursday 13 March 2008, I wrote:
You can set the following HTTP header: Content-Disposition: attachment; filename Where "filename" is the suggested name for saving the file.
This is not correct; it should be: Content-Disposition: attachment; filename=<filename> Where "<filename>" is the suggested name for saving the file. Bye, Maarten
participants (7)
-
Adrian Perez
-
Colin Alston
-
glyph@divmod.com
-
L. Daniel Burr
-
Maarten ter Huurne
-
Suha Onay
-
Suha Onay