Hi again.
First of all: thanks a lot for your answer Massimo, I know you have a lot 
to do, thanks for patiently helping the rookies.

I had already tried that code (saw from an old post) but it dont work too. 
Tried again and it gives the same exact error. This is the full code I used:

import os
import shutil
form = FORM(INPUT(_type='file',_name='myfile'),INPUT(_type='submit'))
if form.accepts(request.vars,session):
    shutil.copyfileobj(form.vars.myfile.file, open(os.path.join(request.
folder,'uploads','filename.wav'),'wb'))
    response.flash = 'form accepted'
elif form.errors:
    response.flash = 'Error'
return dict(form=form)

I tried also with SQLFORM.factory but it is the same.

Small files work, larger files (200 mbs) give this error.

Some tips?



Sábado, 1 de Dezembro de 2012 18:55:01 UTC, Massimo Di Pierro escreveu:
>
> You cannot do:
>
> open(...,'wb').write(form.vars.myfile.file.read())
>
> because this read the entire file in memory before writing it. You need to 
> use
> http://docs.python.org/2/library/shutil.html
> and do
>
> shutil.copyfileobj(form.vars.myfile.file, open(...,'wb'))
>
> Massimo
>
>
> On Friday, 30 November 2012 10:11:48 UTC-6, Paulo wrote:
>>
>> Hi!
>>
>> I'm trying to create a very simple upload field, without any complex 
>> mechanism. A user just uploads a file to a folder in the server (apache), 
>> without web2py changing the file name, and without any db. I have some 
>> dozens of files already in a folder in the server, I just need an upload 
>> form to send new files easly, without having to go personally with an Usb 
>> Pen to the server to copy new files.
>>
>> But I'm having an hard time doing it, and dont know why. With small files 
>> (2mb docx file) it works perfectly. But when uploading a 300mbs wav file it 
>> gives an error ticket:
>> <type 'exceptions.MemoryError'>
>> TRACEBACK
>>
>> 1.
>> 2.
>> 3.
>> 4.
>> 5.
>> 6.
>> 7.
>> 8.
>> 9.
>> 10.
>> 11.
>> 12.
>> 13.
>> 14.
>> 15.
>> 16.
>> 17.
>> 18.
>> 19.
>> 20.
>> 21.
>> 22.
>> 23.
>> 24.
>> 25.
>> 26.
>> 27.
>> 28.
>> 29.
>> 30.
>> 31.
>> 32.
>>
>> Traceback (most recent call last):
>>   File "D:\web2py\gluon\restricted.py", line 212, in restricted
>>     exec ccode in environment
>>   File 
>> "D:/web2py/applications/Upload_Fala_Bracarense/controllers/default.py" 
>> <https://cehum.ilch.uminho.pt/admin/default/edit/Upload_Fala_Bracarense/controllers/default.py>,
>>  line 121, in <module>
>>   File "D:\web2py\gluon\globals.py", line 188, in <lambda>
>>     self._caller = lambda f: f()
>>   File 
>> "D:/web2py/applications/Upload_Fala_Bracarense/controllers/default.py" 
>> <https://cehum.ilch.uminho.pt/admin/default/edit/Upload_Fala_Bracarense/controllers/default.py>,
>>  line 28, in index
>>     form = SQLFORM.factory(Field('myfile', 'upload', 
>> uploadfolder='/static')).process()
>>   File "D:\web2py\gluon\html.py", line 2170, in process
>>     self.validate(**kwargs)
>>   File "D:\web2py\gluon\html.py", line 2109, in validate
>>     if self.accepts(**kwargs):
>>   File "D:\web2py\gluon\sqlhtml.py", line 1281, in accepts
>>     **kwargs
>>   File "D:\web2py\gluon\html.py", line 2022, in accepts
>>     self._traverse(False, hideerror)
>>   File "D:\web2py\gluon\html.py", line 842, in _traverse
>>     newstatus = c._traverse(status, hideerror) and newstatus
>>   File "D:\web2py\gluon\html.py", line 842, in _traverse
>>     newstatus = c._traverse(status, hideerror) and newstatus
>>   File "D:\web2py\gluon\html.py", line 842, in _traverse
>>     newstatus = c._traverse(status, hideerror) and newstatus
>>   File "D:\web2py\gluon\html.py", line 842, in _traverse
>>     newstatus = c._traverse(status, hideerror) and newstatus
>>   File "D:\web2py\gluon\html.py", line 853, in _traverse
>>     self._postprocessing()
>>   File "D:\web2py\gluon\html.py", line 1762, in _postprocessing
>>     _value = str(self['_value'])
>>   File "C:\Python27\Lib\cgi.py", line 515, in __repr__
>>     self.name, self.filename, self.value)
>> MemoryError
>>
>> IN FILE: 
>> D:\WEB2PY\APPLICATIONS\UPLOAD_FALA_BRACARENSE\CONTROLLERS/DEFAULT.PY
>> I have tried a lot of diferent ways. I have read everything I could find 
>> in the web. I found a topic with the same problem but no solution I could 
>> use. Anyone can help with some tips?
>>
>> This the code in the controller:
>>
>> import os
>>
>> def index():
>>     form = FORM(INPUT(_type='file',_name='myfile'),INPUT(_type='submit'))
>>     if form.accepts(request.vars,session):
>>         
>> open(os.path.join(request.folder,'uploads','filename.wav'),'wb').write(form.vars.myfile.file.read())
>>     return dict(form=form)
>>
>> I have tried a lot of different ways, this only an example. I used 
>> SQLFORM.factory {form = SQLFORM.factory(Field('myfile', 'upload', 
>> uploadfolder='/static')).process()}, shutil 
>> {shutil.copyfileobj(request.vars.myfile.file,open(os.path.join(request.folder,'static','filename.txt'),'wb'))},
>>  
>> and a lot of different code variants but none worked. Its allways the same: 
>> with small files it works, with a 200mb file it gives an error.
>>
>>
>> Anyone can help me understand this problem? The max file size I need to 
>> upload is 500mb. It will be used by only one person, with a login, so there 
>> is no need to a complex mechanism, and files need to mantain the same name. 
>> I just need the upload to work. 
>>
>> Thanks and sorry for my bad english.
>>
>>
>>
>>
>> I want a user to be able to upload a file to a directory in the server 
>> (apache), without changing the file name, and wihout databases. A simple 
>> and direct upload, so a friend of mine can store some files in
>>
>

-- 



Reply via email to