I try to store binary file into postgresql through sqlalchemy and file is uploaded from client. A bit google on the error message brings me to this source file:" wrapped object is not bytes or a buffer, this is an error"
binaries = [] for f in request.files.values(): if f and allowed_file(f.filename): fn = secure_filename(f.filename) file_path = os.path.join(basedir, fn) f.save(file_path) #data = f.read() data = open(fn, 'rb').read() binaries.append(psycopg2.Binary(data)) f.close() #does the escaping mytable=mytable( ..., document1 = binaries[0] ... ) #Model class mytable(mydb.Model): document1 = mydb.Column(mydb.LargeBinary())