Downloading file

32 views
Skip to first unread message

ritesh

unread,
Apr 16, 2012, 1:46:34 AM4/16/12
to TurboGears
Hi all,
My scenario of work is to download a file name "devdata.db" from tg
based application, which resides in top directory of project. How can
i achieve it?/ Please help me out.
Thanks in advance.


Regards
Ritesh

Michael Pedersen

unread,
Apr 25, 2012, 12:21:24 AM4/25/12
to turbo...@googlegroups.com
Hi there. There are a number of ways to accomplish this, but I would be very surprised if what you state is what you actually want to do.

The reason I say this is because devdata.db is the name we use for the default database that gets built during development. This database either matters a great deal, and should be kept under lock and key, or it is complete garbage to be rebuilt anytime the mood strikes.

Is this truly your goal? Or is there something else you're trying to accomplish, and this was just a handy filename?

Ritesh

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




--
Michael J. Pedersen
My Online Resume: http://www.icelus.org/ -- Google+ http://plus.ly/pedersen
Google Talk: m.ped...@icelus.org -- Twitter: pedersentg

Moritz Schlarb

unread,
Apr 25, 2012, 2:26:10 PM4/25/12
to turbo...@googlegroups.com
I can give you a snippet for downloading a file that was previously stored in a database.

    @expose(content_type='text/plain')
    def download(self):
        response.headerlist.append(('Content-Disposition', 'attachment;filename=%s' % self.submission.filename))
        return self.submission.source

(The Content-Disposition part will let the browser display the Save As-Dialog insted if displaying the file.)

ritesh

unread,
Apr 26, 2012, 4:24:53 AM4/26/12
to TurboGears
Hi Michael.
its really a very sensitive file which should be kept under lock. but
my project scenario is same to create a copy of that file(devdata.db)
and to download it.
thanks for reply, looking forward for reply.

Ritesh
> Google Talk: m.peder...@icelus.org -- Twitter: pedersentg

Moritz Schlarb

unread,
Apr 26, 2012, 7:05:23 AM4/26/12
to turbo...@googlegroups.com
Well, instead of returning the file from the database, you can use os.open() and return the file iterator (which would be more efficient than first reading the whole file to memory).
You just need to get the correct path for the file, probably by using some __file__ or __package__ magic.

Does that help you?

ritesh

unread,
Apr 27, 2012, 12:44:23 AM4/27/12
to TurboGears
Hi Moritz,
Again it did not helped!!!!!!

Michael Pedersen

unread,
Apr 27, 2012, 12:51:22 AM4/27/12
to turbo...@googlegroups.com
ritesh: you need to give us something here. For most people, most of the time, the info given so far would be enough to figure out the solution.

Why is this not working for you? What result are you expecting, and what result are you actually getting? What version of TurboGears are you using? What version of tg.devtools? Are you in a paster environment, or mod_wsgi? Are you working out of a virtualenv or a buildout, or are you working exclusively with the system installed Python and site-packages? Which operating system are you on? What version of it? Is there any sample code we can look at to see the problem, and maybe help you with?

Right now, all I can say for sure is that you're not getting the results you expect. Without some (ideally, all) of that information, I can't even begin to guess what the problem is, or how to fix it.

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




--
Michael J. Pedersen
Reply all
Reply to author
Forward
0 new messages