Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uploaded Image is not removed #10

Open
nithinmurali opened this issue May 28, 2017 · 3 comments
Open

Uploaded Image is not removed #10

nithinmurali opened this issue May 28, 2017 · 3 comments

Comments

@nithinmurali
Copy link

nithinmurali commented May 28, 2017

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
Copy link

xzitlou commented Aug 14, 2018

Same issue here, any update?

@lehins
Copy link
Owner

lehins commented Aug 14, 2018

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
Copy link

Hise10 commented Dec 7, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants