Implement upload options
Hey thanks for creating what I believe is the correct way to do this!
I'd like to request the ability to specify upload options: My specific use-case is incoming transformations.
I'm not entirely sure how this would be communicated to the storage layer but declaring the options on the model's field would be nice.
With pycloudinary the way they've supported this is to allow you to extend and override CloudinaryField.upload_options(). I don't like this style though as it's preferred to specify options like this as arguments to the field's constructor.
Because we have quite a busy times (just before Christmas), I am not able to look more deeply into this problem, but at first glance, for now you could subclass MediaCloudinaryStorage and overwrite _upload:
class MyCustomMediaCloudinaryStorage(MediaCloudinaryStorage):
def _upload(self, name, content):
// adjust your options here
options = {'use_filename': True, 'resource_type': self._get_resource_type(name), 'tags': self.TAG}
folder = os.path.dirname(name)
if folder:
options['folder'] = folder
return cloudinary.uploader.upload(content, **options)
Then you could use this storage directly in your models, like:
class MyModel(models.Model):
raw_file = models.ImageField(upload_to='/files', blank=True, storage=MyCustomMediaCloudinaryStorage())
You could even overwrite __init__ in your custom storage to allow options kwarg and use it in _upload. I now this is not perfect, and ideally this should be built in the core, but I won't be able to implement this in this year, but if you have time, PR will be appreciated :)