These are chat archives for django/django

11th
Sep 2018
Thomas Matecki
@thomasmatecki
Sep 11 2018 13:14 UTC
Howdy all - anyone one ever struggled with using an imagefield for svg's or come up with an alternative way to store references to them?
Harry Moreno
@morenoh149
Sep 11 2018 16:41 UTC
what's your error?
Thomas Matecki
@thomasmatecki
Sep 11 2018 16:42 UTC
IOError('File does not exist: %s' % name)
Harry Moreno
@morenoh149
Sep 11 2018 16:48 UTC
does the file by that name exist?
Thomas Matecki
@thomasmatecki
Sep 11 2018 17:19 UTC
@morenoh149 - it does not
Harry Moreno
@morenoh149
Sep 11 2018 17:22 UTC
then you need to store it first
Thomas Matecki
@thomasmatecki
Sep 11 2018 17:24 UTC
I think I left out some info here - the app uses and S3 bucket for storage and the files reside there. The ImageField is used to return a url for the file in a json payload
so... the django app should really care if the file exists or not. If it's missing in the storage, then the url will spit out a 404
I thiink I'm looking for a workaround to this: https://code.djangoproject.com/ticket/11084
Harry Moreno
@morenoh149
Sep 11 2018 17:40 UTC
I think you should use amazon's boto python package to upload the image
django's ImageField and FileField are designed to upload binary object's to the api's localfilesytem
Thomas Matecki
@thomasmatecki
Sep 11 2018 17:43 UTC
Yea, we're using the boto library. The missing file is the result of a databases dump across environments. Can't really be avoided.
Harry Moreno
@morenoh149
Sep 11 2018 18:50 UTC
well there you go, the request file isn't there, you must place it there as part of setup or whatever
Thomas Matecki
@thomasmatecki
Sep 11 2018 18:54 UTC
I guess what i'm looking for is more around graceful error handling - my expectation is that I should be able instantiate an instance of a model class with an ImageField without django going out to the respective storage and downloading the file
Harry Moreno
@morenoh149
Sep 11 2018 19:05 UTC
If a model instance exists with an ImageField that is not null, is it reasonable for that to imply that the related resource exists? (thinking out loud)
ideally the field would be null in your environment that lacks the file
Thomas Matecki
@thomasmatecki
Sep 11 2018 19:06 UTC
yea - agreed those are all fair assumptions
Harry Moreno
@morenoh149
Sep 11 2018 19:16 UTC
I've worked on django projects that have involved installation processes. It's not uncommon. Dependency on several databases, running scripts, etc
Thomas Matecki
@thomasmatecki
Sep 11 2018 19:20 UTC
ya... I think we're going to need to hack something out - looks like we've put something in place to allow SVGs to be uploaded in ImageFields
... which aren't ever going to have height and width...
so... django really behaves consistently, except for that