Hello I am building a simple file encryption software and I am facing
issues with files larger than 200KB not being fully uploaded but resulting
in success. I am running nginx server / web2py. However I am pretty sure
it's configuration is set up correctly

Perhaps some one could take a look at my code and offer some advice.



upload_file controller

if form.process(onvalidation=encryptUpload).accepted:
        session.file_id = form.vars.id
        return XML('ajax("%s",[],"status");' % URL('default',
'encrypt_file.load'))



encryptUpload - OnValidation

def encryptUpload(form):

    #validator.validate(form.vars.file_upload.file)
    # on success set hidden fields

    #tmppath = os.path.join(request.folder, 'uploads', 'tmpupf%f.temp.w2p'
% random.random())
    filename = form.vars.file_upload.file

    #filepath = open(tmppath, 'wb')
    #shutil.copyfileobj(filename, filepath)
    #filepath.close()

    #in_filename = str(tmppath)
    outfile = cStringIO.StringIO()

    iv = ''.join(random.choice('0123456789ABCDEF') for i in range(16))
    key =
''.join(random.choice('0123456789!@#$%^&*()ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstufwxyz')
for i in range(32))

    aes = AES.new(key, AES.MODE_CBC, iv)

    chunksize = 64 * 1024
    filename.seek(0, os.SEEK_END)
    filesize = filename.tell() #os.path.getsize(str(tmppath))
    filename.seek(0)

    #with open(in_filename, 'rb') as infile:
    outfile.write(struct.pack('<Q', filesize))
    outfile.write(iv)

    while True:
        chunk = filename.read(chunksize)
        if len(chunk) == 0:
            break
        elif len(chunk) % 16 != 0:
            chunk += " " * (16 - len(chunk) % 16)
            outfile.write(aes.encrypt(chunk))

        outfile.seek(0)
        form.vars.file_upload.file = outfile

    #os.system("srm %s" % tmppath)
    #os.rename(out_filename, filename)

    session.key = key


Any advice is appreciated.

*cheers

-- 
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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to