{ "info": { "author": "YunoJuno", "author_email": "code@yunojuno.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Environment :: Web Environment", "Framework :: Django", "Framework :: Django :: 1.11", "Framework :: Django :: 2.0", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python :: 3.6" ], "description": "django-s3-upload\n================\n\nCompatibility\n-------------\n\nThis library is now Python3 and Django1.11 and above only.\n\nUpload files directly to S3 from Django\n-------------------------------------\n\n[![Build Status](https://travis-ci.org/yunojuno/django-s3upload.svg?branch=master)](https://travis-ci.org/yunojuno/django-s3upload)\n\nThis project allows direct uploading of a file from the browser to AWS S3 via a file input field rendered by Django.\n\nThe uploaded file's URL is then saveable as the value of that field in the database.\n\nThis avoids the problem of uploads timing out when they go via a web server before being handed off to S3.\n\nFeatures include:\n\n* displaying a progress bar\n* support for ACLs (eg, private uploads)\n* support for encrypted-at-rest S3 buckets\n* mimetype and file extension whitelisting\n* specifying different bucket destinations on a per-field basis\n\n## Installation\n\nInstall with Pip:\n\n```pip install django-s3-upload```\n\n## AWS Setup\n\n### Access Credentials\n\nYou have two options of providing access to AWS resources:\n\n1. Add credentials of an IAM user to your Django settings (see below)\n2. Use the EC2 instance profile and its attached IAM role\n\nWhether you are using an IAM user or a role, there needs to be an IAM policy\nin effect that grants permission to upload to S3:\n\n```json\n\"Statement\": [\n {\n \"Effect\": \"Allow\",\n \"Action\": [\"s3:PutObject\", \"s3:PutObjectAcl\"],\n \"Resource\": \"arn:aws:s3:::your-bucket-name/*\"\n }\n]\n```\n\nIf the instance profile is to be used, the IAM role needs to have a\nTrust Relationship configuration applied:\n\n```json\n\"Statement\": [\n\t{\n\t\t\"Effect\": \"Allow\",\n\t\t\"Principal\": {\n\t\t\t\"Service\": \"ec2.amazonaws.com\"\n\t\t},\n\t\t\"Action\": \"sts:AssumeRole\"\n\t}\n]\n```\n\nNote that in order to use the EC2 instance profile, django-s3-upload needs\nto query the EC2 instance metadata using utility functions from the\n[botocore] [] package. You already have `botocore` installed if `boto3`\nis a dependency of your project.\n\n### S3 CORS\n\nSetup a CORS policy on your S3 bucket.\n\n```xml\n\n \n http://yourdomain.com:8080\n POST\n PUT\n 3000\n *\n \n\n```\n\n## Django Setup\n\n### settings.py\n\n```python\nINSTALLED_APPS = [\n ...\n 's3upload',\n ...\n]\n\nTEMPLATES = [{\n ...\n 'APP_DIRS': True,\n ...\n}]\n\n# AWS\n\n# If these are not defined, the EC2 instance profile and IAM role are used.\n# This requires you to add boto3 (or botocore, which is a dependency of boto3)\n# to your project dependencies.\nAWS_ACCESS_KEY_ID = ''\nAWS_SECRET_ACCESS_KEY = ''\n\nAWS_STORAGE_BUCKET_NAME = ''\n\n# The region of your bucket, more info:\n# http://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region\nS3UPLOAD_REGION = 'us-east-1'\n\n# Destinations, with the following keys:\n#\n# key [required] Where to upload the file to, can be either:\n# 1. '/' = Upload to root with the original filename.\n# 2. 'some/path' = Upload to some/path with the original filename.\n# 3. functionName = Pass a function and create your own path/filename.\n# auth [optional] An ACL function to whether the current Django user can perform this action.\n# allowed [optional] List of allowed MIME types.\n# acl [optional] Give the object another ACL rather than 'public-read'.\n# cache_control [optional] Cache control headers, eg 'max-age=2592000'.\n# content_disposition [optional] Useful for sending files as attachments.\n# bucket [optional] Specify a different bucket for this particular object.\n# server_side_encryption [optional] Encryption headers for buckets that require it.\n\nS3UPLOAD_DESTINATIONS = {\n 'example_destination': {\n # REQUIRED\n 'key': 'uploads/images',\n\n # OPTIONAL\n 'auth': lambda u: u.is_staff, # Default allow anybody to upload\n 'allowed_types': ['image/jpeg', 'image/png', 'video/mp4'], # Default allow all mime types\n 'allowed_extensions': ('.jpg', '.jpeg', '.png'), # Defaults to all extensions\n 'bucket': 'pdf-bucket', # Default is 'AWS_STORAGE_BUCKET_NAME'\n 'acl': 'private', # Defaults to 'public-read'\n 'cache_control': 'max-age=2592000', # Default no cache-control\n 'content_disposition': 'attachment', # Default no content disposition\n 'content_length_range': (5000, 20000000), # Default allow any size\n 'server_side_encryption': 'AES256', # Default no encryption\n }\n}\n```\n\n### urls.py\n\n```python\nurlpatterns = [\n url(r'^s3upload/', include('s3upload.urls')),\n]\n```\n\nRun ```python manage.py collectstatic``` if required.\n\n## Use in Django admin\n\n### models.py\n\n```python\nfrom django.db import models\nfrom s3upload.fields import S3UploadField\n\nclass Example(models.Model):\n video = S3UploadField(dest='example_destination')\n```\n\n## Use the widget in a custom form\n\n### forms.py\n\n```python\nfrom django import forms\nfrom s3upload.widgets import S3UploadWidget\n\nclass S3UploadForm(forms.Form):\n images = forms.URLField(widget=S3UploadWidget(dest='example_destination'))\n```\n\n__*Optional.__ You can modify the HTML of the widget by overiding template __s3direct/templates/s3direct-widget.tpl__\n\n### views.py\n\n```python\nfrom django.views.generic import FormView\nfrom .forms import S3UploadForm\n\nclass MyView(FormView):\n template_name = 'form.html'\n form_class = S3UploadForm\n```\n\n### templates/form.html\n\n```html\n\n\n \n s3direct\n {{ form.media }}\n\n\n
{% csrf_token %}\n {{ form.as_p }}\n
\n\n\n```\n\n\n## Examples\n\nExamples of both approaches can be found in the examples folder. To run them:\n```shell\n$ git clone git@github.com:yunojuno/django-s3-upload.git\n$ cd django-s3-upload\n\n# Add your AWS keys to your environment\nexport AWS_ACCESS_KEY_ID='...'\nexport AWS_SECRET_ACCESS_KEY='...'\nexport AWS_STORAGE_BUCKET_NAME='...'\nexport S3DIRECT_REGION='...' # e.g. 'eu-west-1'\n\n$ docker-compose up\n```\n\nVisit ```http://localhost:8000/admin``` to view the admin widget and ```http://localhost:8000/form``` to view the custom form widget.\n\n[botocore]: https://github.com/boto/botocore\n\n\n", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/yunojuno/django-s3-upload", "keywords": "", "license": "", "maintainer": "", "maintainer_email": "", "name": "django-s3-upload", "package_url": "https://pypi.org/project/django-s3-upload/", "platform": "", "project_url": "https://pypi.org/project/django-s3-upload/", "project_urls": { "Homepage": "https://github.com/yunojuno/django-s3-upload" }, "release_url": "https://pypi.org/project/django-s3-upload/0.2.1/", "requires_dist": [ "django (>=1.11)", "boto3" ], "requires_python": "", "summary": "Add direct uploads to S3 to file input fields.", "version": "0.2.1" }, "last_serial": 4221956, "releases": { "0.1.1": [ { "comment_text": "", "digests": { "md5": "f538042efd1c3fa424bf7dc15b86d689", "sha256": "854b73589930864c01a5ad059aba921852867f087215413989a70ba6726c21ec" }, "downloads": -1, "filename": "django_s3_upload-0.1.1-py3-none-any.whl", "has_sig": false, "md5_digest": "f538042efd1c3fa424bf7dc15b86d689", "packagetype": "bdist_wheel", "python_version": "3.6", "requires_python": null, "size": 80574, "upload_time": "2018-02-14T15:40:28", "url": "https://files.pythonhosted.org/packages/24/7f/041886a2c1e7adec662cab6aad207f4312814dafe958dfd3618e77dc6936/django_s3_upload-0.1.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "05b5f6e586caaec134cdf766ccfe7472", "sha256": "1ea6f3c87142e613a7ccb588f64c7579cec3a2297ea8577676302a83ddedbc26" }, "downloads": -1, "filename": "django-s3-upload-0.1.1.tar.gz", "has_sig": false, "md5_digest": "05b5f6e586caaec134cdf766ccfe7472", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 68407, "upload_time": "2018-02-14T15:40:25", "url": "https://files.pythonhosted.org/packages/0e/b4/98a1d99d14b920eb8b3dc2eb189f8f87dd0d0359e477d07656fc840553a2/django-s3-upload-0.1.1.tar.gz" } ], "0.1.2": [ { "comment_text": "", "digests": { "md5": "8ee12f7046079e68369f693f38b81191", "sha256": "a17fcb42679410cf6ab89a4e23348aa3b4a3e4b5661280ead9aad6e08b605fb6" }, "downloads": -1, "filename": "django-s3-upload-0.1.2.tar.gz", "has_sig": false, "md5_digest": "8ee12f7046079e68369f693f38b81191", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 69401, "upload_time": "2018-02-16T16:52:43", "url": "https://files.pythonhosted.org/packages/a3/44/acc6f15a434ad68621b4c4615f833bdc85e0265cc928a769e81b652ec43e/django-s3-upload-0.1.2.tar.gz" } ], "0.2": [ { "comment_text": "", "digests": { "md5": "c4d44d56b6cb99a4ad5bc1d3ee69f973", "sha256": "5d31a41961d271a5df671fd9a347bca67f2ccdcbe109ccb29e815d8927a4027f" }, "downloads": -1, "filename": "django_s3_upload-0.2-py3-none-any.whl", "has_sig": false, "md5_digest": "c4d44d56b6cb99a4ad5bc1d3ee69f973", "packagetype": "bdist_wheel", "python_version": "3.6", "requires_python": null, "size": 89651, "upload_time": "2018-07-05T15:33:55", "url": "https://files.pythonhosted.org/packages/b2/89/0d93d07a1df54e73b38968f0e8157eb786b6a032f7178c3414f8514c6518/django_s3_upload-0.2-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "b73a1762722b4bbdf08d74b8f14c9832", "sha256": "d366c6b04c757423a6e3205eec509430bd057e01db2ca92f81d73a5000e329cd" }, "downloads": -1, "filename": "django-s3-upload-0.2.tar.gz", "has_sig": false, "md5_digest": "b73a1762722b4bbdf08d74b8f14c9832", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 77323, "upload_time": "2018-07-05T15:33:53", "url": "https://files.pythonhosted.org/packages/d0/20/88488ce257ec25807e6979da81e11e6a63ea352eee3f4c9af8ef55efeca6/django-s3-upload-0.2.tar.gz" } ], "0.2.1": [ { "comment_text": "", "digests": { "md5": "a60b9bde2979dc18ff5837bcc071e3b0", "sha256": "2c4f47a849382899b0c09f0f6be2e8b7549fb0cfc40501c25a3d13b0981f4743" }, "downloads": -1, "filename": "django_s3_upload-0.2.1-py3-none-any.whl", "has_sig": false, "md5_digest": "a60b9bde2979dc18ff5837bcc071e3b0", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 71052, "upload_time": "2018-08-30T09:47:14", "url": "https://files.pythonhosted.org/packages/63/cc/94d2529c318e1d4d775c72827d375297da3486f1adb44824404eb40c8c40/django_s3_upload-0.2.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "08a00a6a5e3e3335be72b171b0a9f036", "sha256": "2dd91f946b103afb4a33ef06c31ca166fe93c0bb60616261f467bbf6004f4d76" }, "downloads": -1, "filename": "django-s3-upload-0.2.1.tar.gz", "has_sig": false, "md5_digest": "08a00a6a5e3e3335be72b171b0a9f036", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 63967, "upload_time": "2018-08-30T09:47:16", "url": "https://files.pythonhosted.org/packages/38/fa/c59718b5caa20ae856d722b38ecafc5964e3dce928749597a4d648aec33e/django-s3-upload-0.2.1.tar.gz" } ], "0.2.dev0": [ { "comment_text": "", "digests": { "md5": "9df159f78fef8e056e8e1bea5c88043d", "sha256": "3f9c7d1bd39a9be9b79570bce4b194757cb5d0bb83788b04ebffbd2acfde8063" }, "downloads": -1, "filename": "django_s3_upload-0.2.dev0-py3-none-any.whl", "has_sig": false, "md5_digest": "9df159f78fef8e056e8e1bea5c88043d", "packagetype": "bdist_wheel", "python_version": "3.6", "requires_python": null, "size": 89660, "upload_time": "2018-07-05T15:13:13", "url": "https://files.pythonhosted.org/packages/58/34/76ad2d5c3c54d72acf03f4767b42e22e2b178f1180384ff1db9885e92303/django_s3_upload-0.2.dev0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "5073b1e8c49a709d9bca40fbd634f8ac", "sha256": "bba918c34594f415ecbac05068c30b5a3a6db8a753827cf5793d9a64358a28b0" }, "downloads": -1, "filename": "django-s3-upload-0.2.dev0.tar.gz", "has_sig": false, "md5_digest": "5073b1e8c49a709d9bca40fbd634f8ac", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 77311, "upload_time": "2018-07-05T15:13:11", "url": "https://files.pythonhosted.org/packages/02/1c/65c472eea7c9366b2dce1176c4d892708bb63b859f38db998b603d12aa2a/django-s3-upload-0.2.dev0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "a60b9bde2979dc18ff5837bcc071e3b0", "sha256": "2c4f47a849382899b0c09f0f6be2e8b7549fb0cfc40501c25a3d13b0981f4743" }, "downloads": -1, "filename": "django_s3_upload-0.2.1-py3-none-any.whl", "has_sig": false, "md5_digest": "a60b9bde2979dc18ff5837bcc071e3b0", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 71052, "upload_time": "2018-08-30T09:47:14", "url": "https://files.pythonhosted.org/packages/63/cc/94d2529c318e1d4d775c72827d375297da3486f1adb44824404eb40c8c40/django_s3_upload-0.2.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "08a00a6a5e3e3335be72b171b0a9f036", "sha256": "2dd91f946b103afb4a33ef06c31ca166fe93c0bb60616261f467bbf6004f4d76" }, "downloads": -1, "filename": "django-s3-upload-0.2.1.tar.gz", "has_sig": false, "md5_digest": "08a00a6a5e3e3335be72b171b0a9f036", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 63967, "upload_time": "2018-08-30T09:47:16", "url": "https://files.pythonhosted.org/packages/38/fa/c59718b5caa20ae856d722b38ecafc5964e3dce928749597a4d648aec33e/django-s3-upload-0.2.1.tar.gz" } ] }