GithubHelp home page GithubHelp logo

django-gapc-storage's People

Contributors

brosner avatar coloradocarlos avatar davelowe avatar gcbirzan avatar jacobwegner avatar nakato avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

django-gapc-storage's Issues

Add option to specify cache headers

By default, GCS caches any publicly accessible objects for 3600 seconds.

Especially if a developer is trying to update an existing object (see #4), it may not be desirable to have objects with that long of a cache value.

Either add an option to GoogleCloudStorage to specify cache headers or an additional backend that supports custom cache headers.


GCS_PUBLIC_READ_CACHE_DEFAULT = "public, max-age=3600"

...

class CustomCacheMediaStorage(GoogleCloudStorage):
    """
    Custom subclass of GoogleCloudStorage that allows customization of GCS's
    cache-control header
    """
    cache_control = GCS_PUBLIC_READ_CACHE_DEFAULT

    def _save(self, name, content):
        mimetype, _ = mimetypes.guess_type(os.path.basename(name))
        if mimetype is None:
            mimetype = "application/octet-stream"
        media = MediaIoBaseUpload(content, mimetype)
        req = self.client.objects().insert(
            bucket=self.bucket,
            name=self._prefixed_name(name),
            body={
                "cacheControl": self.cache_control
            },
            media_body=media
        )
        req.execute()
        return name

...

class NoCacheMediaStorage(CustomCacheMediaStorage):
    # never cache
    cache_control = "private, max-age=0"

Configure retries

Configure per backend, set a retry for the following operations:

  • execute
  • media.next_chunk

Object returned by storage._open should conform to the storage backend spec

https://docs.djangoproject.com/en/1.10/howto/custom-file-storage/#django.core.files.storage._open

Called by Storage.open(), this is the actual mechanism the storage class uses to open the file. This must return a File object, though in most cases, you’ll want to return some subclass here that implements logic specific to the backend storage system.

In particular, File.open should support opening or reopening the underlying file:

https://docs.djangoproject.com/en/1.10/ref/files/file/#django.core.files.File.open

Am beginning some work in reopen-files to handle file reopening.

Add option to allow overwrites

Add an option or additional storage backend that allows overwrites.

This is especially useful if the storage backend is being used to update existing objects (similar to what you might do on a local file system opening and writing to an existing file).

Roughly:

    def get_available_name(self, name):
        """
        Always assume a name is available.
        """
        return name

Django < 1.8 compatibility

While the project has always required Django>=1.8, most of the backend has been compatible with earlier versions of Django.

Changes introduced in 148e910 (released in 0.3.0) added the max_length kwarg, which does not exist in earlier versions of Django.

To continue using the backend on earlier versions of Django, override the get_available_name method to remove the max_length kwarg:

def get_available_name(self, name):
    if self.allow_overwrite:
        return name
    return super(GoogleCloudStorage, self).get_available_name(name)

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.