|
View:
New views
4 Messages
—
Rating Filter:
Alert me
|
|
|
TG2 downlaoding a fileI have my tg2 app and i want a user to be able to download an image. They click on download, decide where to save the file and then it downloads. Is there a simple tg2 app for this? Thanks for any help Adam --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "TurboGears" group. To post to this group, send email to turbogears@... To unsubscribe from this group, send email to turbogears+unsubscribe@... For more options, visit this group at http://groups.google.com/group/turbogears?hl=en -~----------~----~----~----~------~----~------~--~--- |
|
|
Re: TG2 downlaoding a fileOn Monday 09 November 2009 12:01:14 adam wrote: > I have my tg2 app and i want a user to be able to download an image. > They click on download, decide where to save the file and then it > downloads. Is there a simple tg2 app for this? This should get you started: http://turbogears.org/2.0/docs/main/ResponseTypes.html Diez --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "TurboGears" group. To post to this group, send email to turbogears@... To unsubscribe from this group, send email to turbogears+unsubscribe@... For more options, visit this group at http://groups.google.com/group/turbogears?hl=en -~----------~----~----~----~------~----~------~--~--- |
|
|
Re: TG2 downlaoding a fileok so i have @expose(content_type=CUSTOM_CONTENT_TYPE) def Download(self,file): username = request.identity['repoze.who.userid'] dir_name = session.get('dir', None) filename = '/home/rubberduckiee/webapps/editor/Xinha/ plugins/ExtendedFileManager/files'+str(dir_name)+'/'+str(file) st = os.stat(filename) size = st[ST_SIZE] rh = response.headers rh['Pragma'] = 'public' # for IE rh['Expires'] = '0' rh['Cache-control'] = 'must-revalidate, post-check=0, pre- check=0' #for IE rh['Cache-control'] = 'max-age=0' #for IE rh['Content-Type'] = 'image/jpg' disposition = 'attachment; filename="'+filename+'"' rh['Content-disposition'] = disposition rh['Content-Transfer-Encoding'] = 'binary' rh['Content-Length'] = size a file downloads but the it fails to open because the file is empty. What am i missing Do i need to read the file to an output? if so how? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "TurboGears" group. To post to this group, send email to turbogears@... To unsubscribe from this group, send email to turbogears+unsubscribe@... For more options, visit this group at http://groups.google.com/group/turbogears?hl=en -~----------~----~----~----~------~----~------~--~--- |
|
|
Re: TG2 downlaoding a fileadam schrieb: > ok so i have > > @expose(content_type=CUSTOM_CONTENT_TYPE) > def Download(self,file): > username = request.identity['repoze.who.userid'] > dir_name = session.get('dir', None) > filename = '/home/rubberduckiee/webapps/editor/Xinha/ > plugins/ExtendedFileManager/files'+str(dir_name)+'/'+str(file) > > st = os.stat(filename) > size = st[ST_SIZE] > > rh = response.headers > rh['Pragma'] = 'public' # for IE > rh['Expires'] = '0' > rh['Cache-control'] = 'must-revalidate, post-check=0, pre- > check=0' #for IE > rh['Cache-control'] = 'max-age=0' #for IE > rh['Content-Type'] = 'image/jpg' > disposition = 'attachment; filename="'+filename+'"' > rh['Content-disposition'] = disposition > rh['Content-Transfer-Encoding'] = 'binary' > rh['Content-Length'] = size > > > a file downloads but the it fails to open because the file is empty. > What am i missing Returning the actual file contents? How else should that happen? And you should get rid of the str() - instead, use the encoding your filesystem uses, and do something like fname = "/path/%s/%s" % (dir_name.encode("utf-8"), file.encode("utf-8")) Diez --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "TurboGears" group. To post to this group, send email to turbogears@... To unsubscribe from this group, send email to turbogears+unsubscribe@... For more options, visit this group at http://groups.google.com/group/turbogears?hl=en -~----------~----~----~----~------~----~------~--~--- |
| Free embeddable forum powered by Nabble | Forum Help |