Can you email me a minimalist app and a sample file to upload to try reproduce the problem?
On May 13, 2:57 pm, Hans <johann.scheibelho...@easytouch-edv.com> wrote: > web2py 1.61.4 > WinXP Pro SP3 > Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit > (Intel)] > > If there is anything I can do to mail it down on my side then let me > know! > > Thanks, > Hans > > On May 13, 9:40 pm, mdipierro <mdipie...@cs.depaul.edu> wrote: > > > The problem is not so much to solve it but to reproduce it. > > > what version of web2py are you running? which os? which python > > version? > > > Massimo > > > On May 13, 2:32 pm, Hans <johann.scheibelho...@easytouch-edv.com> > > wrote: > > > > bumping this one since I still could not fix that. Has anyone managed > > > to solve this yet? > > > > On May 9, 1:09 am, mdipierro <mdipie...@cs.depaul.edu> wrote: > > > > > My bad. This was correct: > > > > shutil.copyfileobj(request.vars.filename.file,open(path,'w')) > > > > > I am surprised you still get a corrupted file. let me run some tests. > > > > > Massimo > > > > > On May 8, 5:05 pm, Hans <johann.scheibelho...@easytouch-edv.com> > > > > wrote: > > > > > > > shutil.copyfileobj(request.vars.filename,open(path,'w')) > > > > > > raises exception: (<type 'exceptions.AttributeError'>, AttributeError > > > > > ('read',), <traceback object at 0x03FC0CB0>) > > > > > > tried also > > > > > shutil.copyfileobj(request.vars.filename.file,open(path,'w')) > > > > > which creates a copy, but again a corrupt copy. > > > > > > This tests now were done just on windows xp. > > > > > > Any other ideas how to solve this? > > > > > > Hans > > > > > > On May 8, 10:29 pm, mdipierro <mdipie...@cs.depaul.edu> wrote: > > > > > > > It may be an issue with buffer size. Try > > > > > > > import shutil > > > > > > shutil.copyfileobj(request.vars.filename,open(path,'w')) > > > > > > > Massimo > > > > > > > On May 8, 2:56 pm, Hans <johann.scheibelho...@easytouch-edv.com> > > > > > > wrote: > > > > > > > > There is a problem with the following code line > > > > > > > > > > > > > > > > > open(path,'w').write(request.vars.filename.file.read()) > > > > > > > > It creates the file 'a_dummy_file_name.xls' but it is not the same > > > > > > > size as the original file, for example: > > > > > > > 6790KB original.xls > > > > > > > 6862KB a_dummy_file_name.xls > > > > > > > > If I try to open the dummy file with excel or open office it says > > > > > > > the > > > > > > > file is corrupt. > > > > > > > I've tried to copy the file manually right after this code line > > > > > > > and > > > > > > > continued execution from there onward...rest works nicely. > > > > > > > > I tried on windows and on ubuntu, seems the same problem. > > > > > > > > Any idea how to solve that issue with the corrupt file (=getting a > > > > > > > exact copy) ? > > > > > > > > thanks, > > > > > > > hans > > > > > > > > On May 7, 10:56 pm, mdipierro <mdipie...@cs.depaul.edu> wrote: > > > > > > > > > This should do > > > > > > > > > def excel_read(): > > > > > > > > result={} > > > > > > > > if request.vars.filename != None: > > > > > > > > try: > > > > > > > > import xlrd > > > > > > > > path=os.path.join > > > > > > > > (request.folder,'private','a_dummy_file_name.xls') > > > > > > > > > > > > > > > > open(path,'w').write(request.vars.filename.file.read()) > > > > > > > > book = xlrd.open_workbook(path) > > > > > > > > result['The number of worksheets is']=book.nsheets > > > > > > > > result["Worksheet name(s)"]= book.sheet_names() > > > > > > > > sh = book.sheet_by_index(0) > > > > > > > > result['sh.name']=sh.name > > > > > > > > result['sh.nrows']=sh.nrows > > > > > > > > result['sh.ncols']=sh.ncols > > > > > > > > result['Cell D30 is']=sh.cell_value(rowx=29, colx=3) > > > > > > > > for rx in range(sh.nrows): > > > > > > > > result['row ' + str(rx)]=sh.row(rx) > > > > > > > > except: > > > > > > > > response.flash = T('excel_read exception') > > > > > > > > return dict(result=result) > > > > > > > > > for you request.vars.filename is a cgi.FieldStorage object. It > > > > > > > > is not > > > > > > > > a named file. > > > > > > > > It containes > > > > > > > > - request.vars.filename.file (a buffered input stream) > > > > > > > > - request.vars.filename.filename (the original filename) > > > > > > > > For you to access it you should read the stream and save it > > > > > > > > with a > > > > > > > > name. Do not use the original filename to avoid directory > > > > > > > > traversal > > > > > > > > attacks. > > > > > > > > > Massimo > > > > > > > > > On May 7, 2:58 pm, Hans <johann.scheibelho...@easytouch-edv.com> > > > > > > > > wrote: > > > > > > > > > > I'm trying to import some content directly from an excel file > > > > > > > > > which > > > > > > > > > the user selects from its local files. I've taken and > > > > > > > > > modified code > > > > > > > > > from the admin controller for retrieving the path/filename > > > > > > > > > thru a nice > > > > > > > > > file selection window. > > > > > > > > > > The problem: I get only the filename of a locked temporary > > > > > > > > > file, not > > > > > > > > > the original filename. If I close the temporary file, to > > > > > > > > > remove the > > > > > > > > > lock, the file is automatically deleted... > > > > > > > > > > I would not mind to work with a temporary copy of the > > > > > > > > > original file, > > > > > > > > > but retrieving the original path/filename thru a similar file > > > > > > > > > selection window would be prefered. How can this be achieved? > > > > > > > > > > Hans > > > > > > > > > P.S. I'm using the xlrd module > > > > > > > > > fromhttp://pypi.python.org/pypi/xlrd > > > > > > > > > > ### viewer ### > > > > > > > > > {{extend 'layout.html'}} > > > > > > > > > <h1>excel_read.html template</h1> > > > > > > > > > > <div class='frame'> > > > > > > > > > <h2>{{=t2.T('Select File')}}</h2> > > > > > > > > > {{=FORM('File: ',INPUT(_type='file',_name='filename'),INPUT > > > > > > > > > (_type='submit', _value='submit'))}} > > > > > > > > > </div> > > > > > > > > > > <div class='frame'> > > > > > > > > > {{=BEAUTIFY(response._vars)}} > > > > > > > > > </div> > > > > > > > > > > ### controller ### > > > > > > > > > def excel_read(): > > > > > > > > > result={} > > > > > > > > > if request.vars.filename != None: > > > > > > > > > try: > > > > > > > > > import xlrd > > > > > > > > > > # >>> can't locate the originally selected path/filename in > > > > > > > > > request.vars.filename <<< > > > > > > > > > book = > > > > > > > > > xlrd.open_workbook(request.vars.filename.file.name) > > > > > > > > > # >>> with a valid path/filename it works <<< > > > > > > > > > book = xlrd.open_workbook('F:/Documents and > > > > > > > > > Settings/Hans/ > > > > > > > > > Desktop/test.xls') > > > > > > > > > > result['The number of worksheets is']=book.nsheets > > > > > > > > > result["Worksheet name(s)"]= book.sheet_names() > > > > > > > > > sh = book.sheet_by_index(0) > > > > > > > > > result['sh.name']=sh.name > > > > > > > > > result['sh.nrows']=sh.nrows > > > > > > > > > result['sh.ncols']=sh.ncols > > > > > > > > > result['Cell D30 is']=sh.cell_value(rowx=29, > > > > > > > > > colx=3) > > > > > > > > > for rx in range(sh.nrows): > > > > > > > > > result['row ' + str(rx)]=sh.row(rx) > > > > > > > > > except: > > > > > > > > > response.flash = T('excel_read exception') > > > > > > > > > return dict(result=result) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "web2py Web Framework" group. To post to this group, send email to web2py@googlegroups.com To unsubscribe from this group, send email to web2py+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/web2py?hl=en -~----------~----~----~----~------~----~------~--~---