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 testsnow_time()# useful for unit testsbasename()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)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| django_s3sign-0.6.5.tar.gz | 29.7 kB | Without provenance | Details for django_s3sign-0.6.5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| django_s3sign-0.6.5-py3-none-any.whl | Python 3 | none | any | Details for django_s3sign-0.6.5-py3-none-any.whl |
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
|
Security for django-s3sign 0.6.5
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.