django-s3sign


Namedjango-s3sign JSON
Version 0.4.0 PyPI version JSON
download
home_pagehttps://github.com/ccnmtl/django-s3sign
SummaryDjango view for AWS S3 signing
upload_time2023-09-21 19:33:29
maintainer
docs_urlNone
authorAnders Pearson
requires_python
licenseGPL3
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            [![Build Status](https://travis-ci.org/ccnmtl/django-s3sign.svg?branch=master)](https://travis-ci.org/ccnmtl/django-s3sign)
[![Coverage Status](https://coveralls.io/repos/github/ccnmtl/django-s3sign/badge.svg?branch=master)](https://coveralls.io/github/ccnmtl/django-s3sign?branch=master)

# django-s3sign
s3 sign view for django

## installation

    $ pip install django-s3sign

## usage

Add `s3sign` to `INSTALLED_APPS`. Subclass `s3sign.views.SignS3View`
and override as needed.

Attributes you can override (and their default values):

```
    name_field = 's3_object_name'
    type_field = 's3_object_type'
    expiration_time = 10
    mime_type_extensions = [
        ('bmp', '.bmp'),
        ('gif', '.gif'),
        ('jpeg', '.jpg'),
        ('pdf', '.pdf'),
        ('png', '.png'),
        ('svg', '.svg'),
        ('webp', '.webp'),
    ]
    default_extension = '.obj'
    root = ''
    path_string = (
        "{root}{now.year:04d}/{now.month:02d}/"
        "{now.day:02d}/{basename}{extension}")
    acl = "public-read"
```

Methods you can override:

* `get_aws_access_key(self)`
* `get_aws_secret_key(self)`
* `get_bucket(self)`
* `get_mimetype(self, request)`
* `extension_from_mimetype(self, mime_type)`
* `now(self)` # useful for unit tests
* `now_time(self)` # useful for unit tests
* `basename(self)`
* `get_object_name(self, extension)`

Most of those should be clear. Read the source if in doubt.


Eg to use a different root path:


```
from s3sign.views import SignS3View
...

class MySignS3View(LoggedInView, SignS3View):
    root = 'uploads/'
```

With a different S3 bucket:

```
class MySignS3View(LoggedInView, SignS3View):
    def get_bucket(self):
        return settings.DIFFERENT_BUCKET_NAME
```

Keeping the uploaded filename instead of doing a random one and
whitelisted extension:

```
class MySignS3View(LoggedInView, SignS3View):
    def basename(self, request):
        filename = request.GET[self.get_name_field()]
        return os.path.basename(filename)

    def extension(self, request):
        filename = request.GET[self.get_name_field()]
        return os.path.splitext(filename)[1]
```


### javascript/forms

The required javascript is also included, so you can include it in
your page with:

    {% load static %}

    <script src="{% static 's3sign/js/s3upload.js' %}"></script>

Your form would then somewhere have a bit like:

    <form method="post">
        <p id="status">
            <strong>Please select a file</strong>
        </p>

        <input type="hidden" name="s3_url" id="uploaded-url" />
        <input type="file" id="file" onchange="s3_upload();"/>
    </form>

And

```
<script>
function s3_upload() {
    var s3upload = new S3Upload({
        file_dom_el: null, // Optional, and overrides file_dom_selector
                           // when present.
        file_dom_selector: '#file',
        s3_sign_put_url: '/sign_s3/', // change this if you route differently
        s3_object_name: $('#file')[0].value,

        onProgress: function(percent, message) {
            $('#status').text('Upload progress: ' + percent + '% ' + message);
        },
        onFinishS3Put: function(url) {
            $('#uploaded-url').val(url);
        },
        onError: function(status) {
            $('#status').text('Upload error: ' + status);
        }
    });
}
</script>
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/ccnmtl/django-s3sign",
    "name": "django-s3sign",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "",
    "author": "Anders Pearson",
    "author_email": "ctl-dev@columbia.edu",
    "download_url": "https://files.pythonhosted.org/packages/5d/c8/b6dbeb92938578e29ea6e908fc0c8fdb3fe12ff36ddf208a4842c808e339/django-s3sign-0.4.0.tar.gz",
    "platform": "any",
    "description": "[![Build Status](https://travis-ci.org/ccnmtl/django-s3sign.svg?branch=master)](https://travis-ci.org/ccnmtl/django-s3sign)\n[![Coverage Status](https://coveralls.io/repos/github/ccnmtl/django-s3sign/badge.svg?branch=master)](https://coveralls.io/github/ccnmtl/django-s3sign?branch=master)\n\n# django-s3sign\ns3 sign view for django\n\n## installation\n\n    $ pip install django-s3sign\n\n## usage\n\nAdd `s3sign` to `INSTALLED_APPS`. Subclass `s3sign.views.SignS3View`\nand override as needed.\n\nAttributes you can override (and their default values):\n\n```\n    name_field = 's3_object_name'\n    type_field = 's3_object_type'\n    expiration_time = 10\n    mime_type_extensions = [\n        ('bmp', '.bmp'),\n        ('gif', '.gif'),\n        ('jpeg', '.jpg'),\n        ('pdf', '.pdf'),\n        ('png', '.png'),\n        ('svg', '.svg'),\n        ('webp', '.webp'),\n    ]\n    default_extension = '.obj'\n    root = ''\n    path_string = (\n        \"{root}{now.year:04d}/{now.month:02d}/\"\n        \"{now.day:02d}/{basename}{extension}\")\n    acl = \"public-read\"\n```\n\nMethods you can override:\n\n* `get_aws_access_key(self)`\n* `get_aws_secret_key(self)`\n* `get_bucket(self)`\n* `get_mimetype(self, request)`\n* `extension_from_mimetype(self, mime_type)`\n* `now(self)` # useful for unit tests\n* `now_time(self)` # useful for unit tests\n* `basename(self)`\n* `get_object_name(self, extension)`\n\nMost of those should be clear. Read the source if in doubt.\n\n\nEg to use a different root path:\n\n\n```\nfrom s3sign.views import SignS3View\n...\n\nclass MySignS3View(LoggedInView, SignS3View):\n    root = 'uploads/'\n```\n\nWith a different S3 bucket:\n\n```\nclass MySignS3View(LoggedInView, SignS3View):\n    def get_bucket(self):\n        return settings.DIFFERENT_BUCKET_NAME\n```\n\nKeeping the uploaded filename instead of doing a random one and\nwhitelisted extension:\n\n```\nclass MySignS3View(LoggedInView, SignS3View):\n    def basename(self, request):\n        filename = request.GET[self.get_name_field()]\n        return os.path.basename(filename)\n\n    def extension(self, request):\n        filename = request.GET[self.get_name_field()]\n        return os.path.splitext(filename)[1]\n```\n\n\n### javascript/forms\n\nThe required javascript is also included, so you can include it in\nyour page with:\n\n    {% load static %}\n\n    <script src=\"{% static 's3sign/js/s3upload.js' %}\"></script>\n\nYour form would then somewhere have a bit like:\n\n    <form method=\"post\">\n        <p id=\"status\">\n            <strong>Please select a file</strong>\n        </p>\n\n        <input type=\"hidden\" name=\"s3_url\" id=\"uploaded-url\" />\n        <input type=\"file\" id=\"file\" onchange=\"s3_upload();\"/>\n    </form>\n\nAnd\n\n```\n<script>\nfunction s3_upload() {\n    var s3upload = new S3Upload({\n        file_dom_el: null, // Optional, and overrides file_dom_selector\n                           // when present.\n        file_dom_selector: '#file',\n        s3_sign_put_url: '/sign_s3/', // change this if you route differently\n        s3_object_name: $('#file')[0].value,\n\n        onProgress: function(percent, message) {\n            $('#status').text('Upload progress: ' + percent + '% ' + message);\n        },\n        onFinishS3Put: function(url) {\n            $('#uploaded-url').val(url);\n        },\n        onError: function(status) {\n            $('#status').text('Upload error: ' + status);\n        }\n    });\n}\n</script>\n```\n",
    "bugtrack_url": null,
    "license": "GPL3",
    "summary": "Django view for AWS S3 signing",
    "version": "0.4.0",
    "project_urls": {
        "Homepage": "https://github.com/ccnmtl/django-s3sign"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d809697c77bd47410832cdf8668ccb0a0b14048a0e37834620ec8d0a42e8d1af",
                "md5": "8ce9b809abd60e988ffe3daba6bf4231",
                "sha256": "49146c3869e2322655e324adccc5e00338647343154a17cf605b0cc41474c866"
            },
            "downloads": -1,
            "filename": "django_s3sign-0.4.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "8ce9b809abd60e988ffe3daba6bf4231",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 37834,
            "upload_time": "2023-09-21T19:33:27",
            "upload_time_iso_8601": "2023-09-21T19:33:27.986234Z",
            "url": "https://files.pythonhosted.org/packages/d8/09/697c77bd47410832cdf8668ccb0a0b14048a0e37834620ec8d0a42e8d1af/django_s3sign-0.4.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "5dc8b6dbeb92938578e29ea6e908fc0c8fdb3fe12ff36ddf208a4842c808e339",
                "md5": "6aa3e52cad13876a3c5782e8eb725762",
                "sha256": "40e52a053569a0173cb6f12aafc2d8ebe3c83f6978c0a4dbb6bd014242a7313a"
            },
            "downloads": -1,
            "filename": "django-s3sign-0.4.0.tar.gz",
            "has_sig": false,
            "md5_digest": "6aa3e52cad13876a3c5782e8eb725762",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 31997,
            "upload_time": "2023-09-21T19:33:29",
            "upload_time_iso_8601": "2023-09-21T19:33:29.490255Z",
            "url": "https://files.pythonhosted.org/packages/5d/c8/b6dbeb92938578e29ea6e908fc0c8fdb3fe12ff36ddf208a4842c808e339/django-s3sign-0.4.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-09-21 19:33:29",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "ccnmtl",
    "github_project": "django-s3sign",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "django-s3sign"
}
        
Elapsed time: 0.13321s