Skip to main content

Build Status

django-s3sign

s3 sign view for django. Facilitates file uploads to AWS S3.

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
    default_extension = '.obj'
    root = ''
    path_string = (
        "{root}{now.year:04d}/{now.month:02d}/"
        "{now.day:02d}/{basename}{extension}")

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() # useful for unit tests
  • now_time() # useful for unit tests
  • basename()
  • 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() {
    const 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>

Metadata

Release files for django-s3sign 0.6.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-s3sign 0.6.5
File Size Uploaded
django_s3sign-0.6.5.tar.gz 29.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-s3sign 0.6.5
File Interpreter ABI Platform
django_s3sign-0.6.5-py3-none-any.whl Python 3 none any Details

Total release size: 62.0 kB

Release files / django_s3sign-0.6.5.tar.gz

Download URL django_s3sign-0.6.5.tar.gz
Size 29.7 kB
Tags Source
SHA-256 checksum
How to use checksums
47f0d8ab65a3e5dd4fe9022c6ed84b9ec13bd086ba147e29c1f71c2c275f2503
BLAKE2b-256 checksum
How to use checksums
d7f31afcd1704623f2070e4e16b3c9a15b8c6968eabbf73769c64cd0fe5bc497
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Release files / django_s3sign-0.6.5-py3-none-any.whl

Download URL django_s3sign-0.6.5-py3-none-any.whl
Size 32.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
17d72ce63f2e8da610a177b7152892e8b1b790b5ece1bdf9cbcbd312b2c33cb2
BLAKE2b-256 checksum
How to use checksums
dc888099c177a8f2a32f4977f11ca7adfce36512f5a1ad209b1ca4101068469e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Release history Release notifications | RSS feed

This release

0.6.5 This release

2 release files

0.6.4

2 release files

0.6.3

2 release files

0.6.2

2 release files

0.6.1

2 release files

0.6.0

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.3

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.9

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

1 release file

0.1.1

1 release file

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page