Giter Club home page Giter Club logo

Comments (3)

ivanvenosdel avatar ivanvenosdel commented on June 20, 2024 1

Kloddant's PR will work fine for the model field but will encounter trouble with the URLField examples.

So if you are coming here in the latter camp, here is how to fix that case without waiting for library changes. This approach takes the philosophy of sanitizing the file names on the server rather than letting S3 play fast and loose with them.

This would go in your settings.py.

import functools

def safe_key(prefix, file_name):  
    file_name = file_name.replace(' ', '_')
    # Plus any additional file name customization you want.
    key = '/'.join([prefix, file_name])
    return key

S3DIRECT_DESTINATIONS = {
    'a_destination': [
        functools.partial(safe_key, 'someprefix'),
        lambda u: u.is_authenticated(),
        ['image/jpeg', 'image/png'],
        'public-read',
        'somebucket',
    ],
    'another_destination': [
        functools.partial(safe_key, 'anotherprefix'),
        lambda u: u.is_authenticated(),
        ['image/jpeg', 'image/png'],
        'public-read',
        'somebucket',
    ],
}

from django-s3direct.

bradleyg avatar bradleyg commented on June 20, 2024

Thanks, possible to do a pull request?

from django-s3direct.

kloddant avatar kloddant commented on June 20, 2024

Okay, just did. And thank you! This project has saved a great deal of time for me.

from django-s3direct.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.