If you read the file (csv.reader(sent_file) or sent_file.readlines(), etc.) 
you then have to rewind it:

sent_file.seek(0)




On Tuesday, 23 July 2013 21:18:07 UTC-5, __pyslan__ wrote:
>
> Hello everybody.
>
>
> I'm trying upload files with SQLFORM.grid.
>
> Model:
>
> FilesUploaded = db.define_table('files_uploaded',
>     Field('name', notnull=True, label=T("Name")),
>     Field('file_name', 'upload', notnull=False, label=T("File")),
>     Field('owner_group', 'reference auth_group', notnull=True, label=T("Owner 
> Group")),
>     Field('creation', 'datetime', notnull=True, 
> default=datetime.datetime.now(), label=T("Creation")),
>     format='%(name)s')
>
>
> Constraints:
>
> FilesUploaded.owner_group.compute = lambda row: 
> auth.user_groups.keys()[0]FilesUploaded.owner_group.readable = 
> FalseFilesUploaded.owner_group.writable = False
> FilesUploaded.creation.writable = FalseFilesUploaded.file_name.requires = 
> IS_LENGTH(maxsize=(1024*(1024*5)), error_message=T("Send files with a maximum 
> size of") + " 5GB.")
>
>
> def upload_validation(form):
>     sent_file = request.vars.file_name.file
>     file_name = request.vars.file_name.filename
>     extension_file = file_name.split('.')[-1]
>
>     if extension_file == 'csv':
>         import csv
>         file_lines = list(csv.reader(sent_file, delimiter=',', 
> quoting=csv.QUOTE_NONE))
>     elif extension_file == 'txt':
>         file_lines = list(sent_file.readlines())
>     else:
>         form.errors.file_name = T("The file types supported are .csv or .txt")
>         return False
>         
>     max_lines = 100000
>
>     if len(lines) > max_lines:
>         form.errors.file_name = T("Maximum quantity per upload is %(qty)s 
> lines.") % dict(qty = max_lines)
>         return False
>
> Controller:
>
> form=SQLFORM.grid(query, csv=False, fields=fields, links=links, 
> user_signature=True, onvalidation=upload_validation)
>
>
>
> 1 -> The file size is 0 bytes after upload.
> 2 -> But, if I put the command "print request" on the last line of 
> upload_validation function, works fine.
>
>
> If anyone can help me, I appreciate!
>
>
> __pyslan__
>
>
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to