resume upload wsgi script

gert gert.cuykens at gmail.com
Sun Aug 9 08:14:33 EDT 2009


I working on a resume upload script and encountered the following
problems

sql: Could not decode to UTF-8 column 'SUBSTR(picture,?)' with text
'\ufffd\ufff
d\ufffd\ufffd↑!Exif------------Ef1gL6KM7Ij5ae0gL6KM7cH2cH2GI3
Content-Disposition: form-data; name="Filename"

DSC00013.JPG
------------Ef1

when I dont use SUBSTR or  COALESCE and || it works

def application(environ, response):
    range=environ.get('HTTP_RANGE','bytes=0-').replace
('bytes=','').split(',')
    offset=[]
    for r in range: offset.append(r.split('-'))
    db.execute('UPDATE users SET picture=SUBSTR(picture,?) WHERE
uid=?', (offset[0][0],s.UID))

    chunk=environ['wsgi.input'].read(int(environ
['CONTENT_LENGTH'])).decode('latin1')
    db.execute('UPDATE users SET picture=COALESCE(picture,?)||? WHERE
uid=?', (''.encode('latin1'),chunk.encode('latin1'), s.UID))

    #while True:
    #      chunk=environ['wsgi.input'].read(8192).decode('latin1')
    #      if not chunk: break
    #      db.execute("UPDATE users SET picture=COALESCE
(picture,'')||? WHERE uid=?", (chunk, s.UID))

the following is the POST clean up when PUT is not used, does anyone
know how to do this without loading the complete blob into memory ?

    db.execute('SELECT picture FROM users WHERE uid=?',(s.UID,))
    f=db.fetch()
    b=environ['CONTENT_TYPE'].split('boundary=')[1]
    p=search(b+r'.*?Content-Type: application/octet-stream\r\n\r\n(.*?)
\r\n--'+b,f[0][0].decode('latin1'),DOTALL).group(1)
    db.execute('UPDATE users SET picture=? WHERE uid=?', (p.encode
('latin1'), s.UID))




More information about the Python-list mailing list