跳转到主要内容

Django小部件库,用于直接通过浏览器上传到S3

项目描述

joist

PyPI version shields.io

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://:8000https://: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 查看哈希值)

上传时间 Python 2 Python 3

支持者

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误记录 StatusPage StatusPage 状态页面