0

I use cloudinary as the default media storage for my Django project so I just setup it like this:

settings.py

   INSTALLED_APPS = [
       'cloudinary'
   ]

   DEFAULT_FILE_STORAGE = 'cloudinary_storage.storage.MediaCloudinaryStorage'

   CLOUDINARY_STORAGE = {
      'CLOUD_NAME': os.environ.get('CLOUDINARY_STORAGE.CLOUD_NAME'),    # env is set right
      'API_KEY': os.environ.get('CLOUDINARY_STORAGE.API_KEY'),
      'API_SECRET': os.environ.get('CLOUDINARY_STORAGE.API_SECRET'),
   }

so now if I want to setup an ImageField I have no problems with that just with default Django syntax:

   image = ImageField(upload_to=get_image_upload_path,
                      max_length=255)

but when I want to store a file in my way it's video file:

   video = FileField(upload_to=get_video_upload_path,
                     max_length=255)

I get this error: Invalid image file which means that Django using cloudinary storage tries to upload this file as an image what's set as the default behavior to cloudinary.

So my questions is if there is anyway to tell cloudinary gloabally to automatically decide what type of the file is?

Alex Burla
  • 127
  • 1
  • 14
  • Accept advices about the topic header :) – Alex Burla Feb 18 '21 at 16:46
  • I haven't found any ways to do that. But if u're looking for solution I made a mixin class where realized choising between CloudinaryVideoField and FileField depending on a custom global setting so I can use it in my models. – Alex Burla May 29 '21 at 20:43

0 Answers0