lundi 28 août 2017

Managing Arbitrary Uploads

I am working on a web project which manages collections of arbitrary things. Collections are made up of arbitrary, user-defined fields and each field is of a given type. The type of the field affects how the data is stored and interpreted. For instance, a field of type "text" would be stored in a database as TEXT or VARCHAR and would be rendered to the user as a text input or text area.

I want to add support for more complicated field types that represent files. For instance, I want an "image" type which stores/displays an image file. The system I have developed uses "plugins" to handle each field type which are in charge of how data is represented in the database and how this data is displayed to the user (e.g. a field of type "color" is stored in a database VARCHAR column as hex and displayed to the user in a DOM element with the background color set to that hex value). I want the design to work (as closely as possible) as follows:

  • The user should be able to upload a new file to a given field in a collection item and have that upload confirmed (success/failure).
  • The upload is not "applied" until the user saves the changes to the item, once applied those uploads will now be associated to the fields of the item
  • If the user uploads new files and doesn't save changes, these newly uploaded files are deleted from the server
  • Once a new upload has been saved, the previous file (the one that this upload replaced) should be deleted from the server
  • File uploads need to be of any type and the plugin for each type handles what types are allowed for it and how the file is displayed
  • Some reference to the physical file needs to be stored in the database

I have spent a ton of time thinking through many different ways of implementing something like this but have not been able to settle on anything that seems robust, extensible, reliable, and manageable. I would greatly appreciate suggestions based upon best design practices and experience. Please let me know if I need to clarify anything.

Thanks, Patrick




Aucun commentaire:

Enregistrer un commentaire