Skip to content

Slugify file names before saving #38

Closed
@srus

Description

Just to say that I found a bug in a early version of this library, when you try to upload a picture that includes the symbol '#' in the file name. For example:

Photo on 2012-04-05 at 15.56 #3.jpg

These kind of file names are typical when using MacBook webcams.

So, I solved that using slugify() with the file name, in order to avoid strange characters. Something like:

# avatar/views.py
def add(...):
    # ...
    file_name = os.path.splitext(image_file.name)
    name = file_name[0]
    extension = file_name[1]
    new_file_name = slugify(name) + extension
    avatar.avatar.save(new_file_name, image_file)
    # ...

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions