[Flask] Uploading image into MySQL Blob

Matt Shields matt at mattshields.org
Wed May 18 11:58:39 EDT 2016


Actually, disregard my question.  I ended up using a AWS S3 bucket to host
the images.  I was able to convert the code in a matter of minutes,
compared to the 2 days I wasted trying to get images uploaded into MySQL.

Matt

On Wed, May 18, 2016 at 11:30 AM, Ioannis Pinakoulakis <
giannis.pin at gmail.com> wrote:

> 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/flask/attachments/20160518/45f29e2d/attachment.html>


More information about the Flask mailing list