Django小部件库,用于直接通过浏览器上传到S3
项目描述
joist
Joist是一个Django小部件库,通过浏览器直接上传到S3桶,而不是通过服务器。它扩展了django-storages库的S3文件存储功能
安装
pip install django-storages joist
通过源码
pip install -e 'git+https://github.com/danlamanna/joist.git#egg=joist'
配置
Joist依赖于django-storages的S3配置(参见https://django-storages.readthedocs.io/en/latest/backends/amazon-S3.html),以下设置被使用
键 | 描述 |
---|---|
AWS_ACCESS_KEY_ID | 您的Amazon Web Services访问密钥,作为字符串。 |
AWS_SECRET_ACCESS_KEY | 您的Amazon Web Services秘密访问密钥,作为字符串。 |
AWS_S3_REGION_NAME | 要使用的AWS S3区域名称(例如,eu-west-1) |
AWS_STORAGE_BUCKET_NAME | 您的Amazon Web Services存储桶名称,作为字符串。(必需) |
其他设置
键 | 描述 |
---|---|
JOIST_UPLOAD_STS_ARN | 要使用的STS Arn角色(必需) |
楼层上传持续时间 | 上传令牌有效时长(以秒为单位,默认:60*60*12 = 12小时 ) |
楼层上传前缀 | 文件应存储的前缀(默认:'' ) |
楼层API基础URL | 服务器URL托管在API前缀下(默认:/api/joist ) |
用法
设置
将 joist
添加到已安装应用程序列表中
settings.py
:
INSTALLED_APPS = [
...
'rest_framework',
'rest_framework.authtoken',
'joist',
]
此外,由于该字段需要额外的REST端点,因此必须将它们添加到 urlpatterns
中
urls.py
urlpatterns = [
...
path('api/joist/', include('joist.urls')),
]
模型定义
而不是
photo = models.FileField()
使用
from joist.models import S3FileField
photo = S3FileField()
结果是,一旦用户在文件选择器中选择文件,它将自动在客户端上传到S3。
信号
当Joist的REST API被调用时,Joist会发出两个信号
joist_upload_prepare(name: str, object_key: str)
joist_upload_finalize(name: str, object_key: str, status: string)
开发环境
需求
- Terraform
- AWS CLI
- Python 3.7
- node
初始化AWS
登录AWS控制台并创建API访问密钥
aws configure
运行Terraform
cd terraform
terraform init
terraform workspace new <NAME>
terraform apply
创建环境文件
cd terraform
terraform output > ../example/.env
注意
- 编辑
.env
文件并删除=
字符周围的空格
初始化Django和Python仓库
pipenv --python=3
pipenv install -r requirements.txt example/requirements.txt
pip install -e .
cd example
./manage.py migrate
./manage.py createsuperuser
初始化仓库预提交
pipenv shell
pip install pre-commit
pre-commit install
初始化小部件客户端
cd client
npm install
npm run dev
初始化测试Vue客户端
cd example-client
npm install
待办事项
cd example
./manager.py runserver
--> 在 https://:8000 和 https://:8000/admin 运行
示例blob表单
cd example-client
npm run serve
--> 在 https://:8080 运行
发布
pipenv shell
pip install bumpversion
bumpversion minor
待办事项:npm发布
项目详情
下载文件
为您的平台下载文件。如果您不确定选择哪个,请了解更多关于 安装包 的信息。
源分布
joist-0.0.2.tar.gz (106.1 kB 查看哈希值)
构建分布
joist-0.0.2-py2.py3-none-any.whl (102.3 kB 查看哈希值)
关闭
joist-0.0.2.tar.gz的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 95f2e9491f84b45f79b82119a18a4d39dd11ce2ebbc886781d9a084f0fbd09da |
|
MD5 | 79ac825da3dda37d2c412a5e9a51f35c |
|
BLAKE2b-256 | 426c76099ae748c85187a3338806a76ed8d0f679f00895e2a2de99510b3c21bf |
关闭
joist-0.0.2-py2.py3-none-any.whl的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 4c3650b9df4e8536bb140339e0c6653971a7106b6f84b1ba5a608cb2ff12a977 |
|
MD5 | be477123f27a097cc7e853980c5d11d5 |
|
BLAKE2b-256 | 42e0d0f8f19dfa55b63043ab995a61215a4c5ef206c93cc1529d891f7048a6a3 |