def Upload():
from gluon.contenttype import contenttype
import os, stat
form=SQLFORM(db.image)
if form.accepts(request.vars, session):
file_handler = request.vars.pic ### this if a cgi.FieldStorage
file_path = os.path.join(request.folder,
'uploads/',form.vars.pic)
raw_file_size = file_handler.?file_size()
MIME_Version = ?get_MIME()
Content_ID = file_handler.?file_handler()
Content_Type = file_handler.?file_type()
file_header = ?get_Phys_File_Header(file_handler)
db(db.image.id==form.vars.id).update(
physical_file_name = file_path,
file_extension = file_path.split('.')[-1],
file_size = os.stat(file_path)[stat.ST_SIZE],
Content_Type = contenttype(file_name),
MIME_Version = ?
Content_ID = ?,
file_header = ?,
)
response.flash = 'File Uploaded'
return dict(form=form)
I fixed some. Not all because I am not sure what those fields should
contain.
On Nov 9, 3:52 pm, Alexandre Augusto <[email protected]> wrote:
> Hi Massimo and Cesar. First of all another one zillion thxz to the
> Extremely Amazing Framework ever created !
>
> I have a sittuation that is not the same as
> Cesar:http://groups.google.com/group/web2py/browse_thread/thread/c83cd69dee...
> but somehow it is related..
> and I did spent like 6 days trying many things and I could not make it
> right... hope you could help me out..
> and maybe this solves many others problems...
>
> *In a nut shell, I'm trying to upload the file, store it on the
> database (using the two fields upload and blob ),
> and save all meta-data and common information to different fields on
> the same record *
>
> *By meta-data I refer to file Mime types*
> 1. MIME-Version
> 2. Content-ID
> 3. Content-Type
> [ 4. File header signature, extracted from the file first data
> block -- not sure one of the 3 fields above provide this incase not ]
>
> *and common infomation*
> I mean all user information that could be associated to the file:
>
> 5. Full file name ( 'C:\My Documents\pics\agape.jpg' )
> 6. File Extension ( '.jpg' )
> 7. File Size ( ' 230 kb ' )
> n. ...or any other metadata information available for the file
>
> I could make the upload/ and blob/ work but I'm not having success to
> gather and extract this information from the file at the same time I'm
> uploading and storing it on the DB..
>
> This is for my Computer Science Bachelor Graduation Work at Unip, São
> Paulo University, once i get it more mature I'm going to release it
> to the community, as I'm aiming to create an Open Source Project
> similar what happened to Instant Press but on a different scope
> application some sort of ECM tool.. Even being aware that may not be
> wise to store all these and some could be derivative from other
> fields, I need to make this work for the proof of concept to develop
> other concepts in the project.....
>
> So my model is like this
>
> # Model
> db.define_table("image",
> Field('pic','upload',default=''),
> Field('file','upload', default="", autodelete=True,
> uploadfield='file_binary_data') ,
> Field('file_binary_data', 'blob'),
> Field('physical_file_name'), # the full file name.. is it possible
> grab the folder from where it was uploaded ?
> Field('file_extension'),
> Field('file_size'),
> Field('MIME_Version'),
> Field('Content_ID'),
> Field('Content_Type'),
> Field('file_header'), #File header footprint extracted from X top
> chars from file
> )
>
> #Controller
> def Upload():
> form=SQLFORM(db.image)
>
> if form.accepts(request.vars, session):
>
> file_name = request.vars.pic
>
> try: ext = re.compile('\.\w+
> $').findall(file_name.filename.strip())[0]
> except IndexError: ext = '.txt'
>
> #pic_filename = 'image.'+'pic.'+str(random.random())[2:] + ext
> #pic_filename = 'image.'+'pic.' +
> str(uuid.uuid4()).replace('-','') + ext
>
> #pic_filename = pic.filename
> file_path = os.path.join(request.folder, 'uploads/',
> file_name)
> file_handler = open(file_path,'wb')
> file_handler.close()
>
> raw_file_size = file_handler.?file_size()
> MIME_Version = ?get_MIME()
> Content_ID = file_handler.?file_handler()
> Content_Type = file_handler.?file_type()
> file_header = ?get_Phys_File_Header(file_handler)
>
> image_id = db.image.insert(
> pic = file_name.uuid64 ,
> file_binary_data = file_name ,
> physical_file_name = file_path ,
> file_extension = ext ,
> file_size = raw_file_size ,
> MIME_Version = MIME_Version ,
> Content_ID = Content_ID ,
> Content_Type = Content_Type ,
> file_header = file_header ,
> )
>
> response.flash = 'File Uploaded'
>
> return dict(form=form)
>
> #######
>
> I tried to update the response.post_var trying to avoid the manual
> record insert directly but the change didn't went to db
>
> on the manual insert I added fictitious properties and method trying
> to access the properties array directly of
> FieldStorage object.. they are marked with questions marks (?) to
> indicate where I'm looking for help
>
> Is it possible to do store everything on the same moment file is
> uploaded ?
> Any help on how to store these columns are welcome ! thanks much
>
> _______________________________________________________________
> Alexandre A. Almeida
> Ax3
>
> "Any intelligent fool can make things bigger and more complex... It
> takes a touch of genius - and a lot of courage to move in the opposite
> direction." -- Albert Einstein