Sergo
Sergo

Reputation: 176

Cloudinary upload image from Django admin panel from two or more databases

everyone. I decide to use Cloudinary for storing images. This is my model field with image:

avatar = models.ImageField(upload_to='avatar/', default='avatar/default.png', blank=True)

All works fine for me, but I have one little issue. When I uploaded the image from admin panel, cloudinary upload it to my cloudinary folder 'avatar' with some modified name, for example: 'july2022_kda4th' or 'july2022_aidkdk' But when I uploaded this image from admin panel of another database (production), cloudinary upload the image with another name. So, I have two similar images in cloudinary. It's not convenient. How can I fix it?

Upvotes: 0

Views: 338

Answers (1)

Tom
Tom

Reputation: 111

By default, if you don't supply a public_id in the upload API call, a random string is assigned to the asset. You can read more here: https://cloudinary.com/documentation/upload_images#public_id.

It sounds like you want to use the asset filename as the public_id so what you can do is:

  • In forms set use_filename=true and unique_filename=false as described in this link

OR if above is not working you can

  1. Create an upload preset https://cloudinary.com/documentation/upload_presets
  2. Enable Use filename or externally defined Public ID: option
  3. Disable Unique filename:
  4. Set this preset as the default upload API/UI (https://cloudinary.com/documentation/upload_presets#default_upload_presets) or include this upload_preset in your upload call

Upvotes: 1

Related Questions