lehins / django-smartfields

Django Model Fields that are smart.
MIT License
98 stars 13 forks source link

Uploaded Image is not removed #10

Open nithinmurali opened 7 years ago

nithinmurali commented 7 years ago

Django version : 1.11.1

This is the code of model

    avatar = fields.ImageField(dependencies=[
        FileDependency(processor=ImageProcessor(format='JPEG',
                                                    scale={'max_width': 300, 'max_height': 300}))], blank=True)

I am saving the image as baes64 encoded image using

image_data = b64decode(imgstr)
merchant.avatar = ContentFile(image_data, name='{}.{}'.format(uuid4().hex, ext))
merchant.save()

But the problem is, i am trying to upload the images to a avatar folder in media, but the what is happening is it is creating another folder avatar in media/avatar folder. and is saving the jpg file in media/avatar/avatar folder. Also the uploaded png file is still present in in media/avatar .

xzitlou commented 6 years ago

Same issue here, any update?

lehins commented 6 years ago

I don't really have a way to replicate this. This doesn't seem like a critical issue, despite that fact, I'll try to check it out at some point.

What I can recommend for now is FileDependency accepts upload_to argument, which works much the same way as the one accepted by FileField or ImageField: https://github.com/lehins/django-smartfields/blob/master/smartfields/dependencies.py#L244 So the behavior you are describing should be easily avoided, unless there is something new in django that is preventing it from functioning properly.

I don't remember right now if I made it possible for the original to be discarded after the conversion, since I wanted to keep those just in case if I needed to change some settings in dependencies and reconvert the original, eg. resize to different dimensions.

On a side note there is also a helper class UploadTo that can be used to generate unique filenames in a way that is nicely organized: https://github.com/lehins/django-smartfields/blob/master/smartfields/utils.py#L75

Hise10 commented 4 years ago

same thing happening now django version 2.2.7 even after upload to file dependency added