Binder has FileField/ImageField support. In short, you do a multipart/form-data POST /api/model/5/filefield/ to update the file on a model instance.
There are problems:
The code deletes the old file before saving the new one. If the request fails for whatever reason, you're left with the new file (wrong), a damaged file (wrong), or no file at all (also wrong).
Certain operations on the files (i.e. rotating of images) leave the old file forever, leading to dangling files taking up space.
There is no caching where you want it (the files are served from /api/ which has Cache-Control: no-store)
There is caching where you don't want it (updating the file doesn't change the URL, and browsers may and do cache this within a single page load).
The files are served by Binder/Django, tying up an expensive worker process for slow clients.
Probably more stuff.
We want a long-term direction for how to refactor this so we can fix all these problems.
Some random thoughts:
Perhaps Binder can specify a Cache-Control header for file GETs. If nginx then doesn't override this, it would provide caching where desired.
Perhaps we should use a UUID or image hash in the URL. This would disable unwanted caching and help with wanted caching.
We must fix the delete-before-save semantics.
We should consider using a separate model for file objects; e.g. a File with fields for the hash, change date, image dimensions, etc. Models could then use an FK to File instead of a FileField. Permissions are a concern.
We should investigate whether we can use nginx internal redirects by default for image fields.
Binder has FileField/ImageField support. In short, you do a multipart/form-data
POST /api/model/5/filefield/
to update the file on a model instance.There are problems:
/api/
which hasCache-Control: no-store
)We want a long-term direction for how to refactor this so we can fix all these problems.
Some random thoughts:
Cache-Control
header for file GETs. If nginx then doesn't override this, it would provide caching where desired.File
with fields for the hash, change date, image dimensions, etc. Models could then use an FK toFile
instead of aFileField
. Permissions are a concern.