[Flask] Uploading image into MySQL Blob

Ioannis Pinakoulakis giannis.pin at gmail.com
Wed May 18 11:30:48 EDT 2016


Hi Matt,

Firstly, I would like to mention that a better approach would be to not store the image in the database, rather a link that points to the each image probably in the file system. This will speed up your application, since 1) you query the database for less data, 2) reading from the file system is faster and finally 3) in case you want to move the images on a CDN or in general serve them from a separate server then this does not block you. Thus easier migrations.

Back to your original problem. Do you get any error or something?

Ioannis

18 maj 2016, 15:48, ο/η Matt Shields <matt at mattshields.org> έγραψε:

> I'm trying to get an image uploaded through a form and inserted into a Blob field in MySQL.  This doesn't seem to work.  What's wrong?
> 
> clientid = request.form['clientid']
> file = request.files['logo']
> path = config.app_path()
> filename = "%s-logo.png" % clientid
> local_file = "%s/static/%s" % (path, filename)
> file.save(local_file)
> sql = "UPDATE client SET logo = LOAD_FILE('%s') WHERE clientid = '%s'" % (local_file, clientid)
> dbQuery(sql)   #This is custom function to run a sql query.
> 
> Matt
> _______________________________________________
> Flask mailing list
> Flask at python.org
> https://mail.python.org/mailman/listinfo/flask


More information about the Flask mailing list