# django-oss-storage **Repository Path**: shouyong/django-oss-storage ## Basic Information - **Project Name**: django-oss-storage - **Description**: 版权归:https://github.com/aliyun/django-oss-storage所有。 - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 3 - **Forks**: 0 - **Created**: 2018-04-26 - **Last Updated**: 2022-06-06 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README Django AliCloud OSS Storage ========================= **django-oss-storage** provides a Django AliCloud OSS file storage. Features ======== - Support Django 2.0+ - Django file storage for AliCloud OSS - Django static file storage for AliCloud OSS - Works in Python 3.6+ 安装 ============ * Install .. code-block:: bash $ pip install git+https://gitee.com/enlangs/django-oss-storage.git - Add ``'django_oss_storage'`` to your ``INSTALLED_APPS`` setting - Set your ``DEFAULT_FILE_STORAGE`` setting to ``"django_oss_storage.backends.OssMediaStorage"`` - Set your ``STATICFILES_STORAGE`` setting to ``"django_oss_storage.backends.OssStaticStorage"`` - Configure your AliCloud OSS settings (Refer below). Use the following settings for file storage. .. code-block:: bash # 配置静态文件都是用OSS存储; STATICFILES_STORAGE = 'django_oss_storage.backends.OssStaticStorage' # 配置上传文件使用OSS存储,如:ImageField、FileField DEFAULT_FILE_STORAGE = 'django_oss_storage.backends.OssMediaStorage' Authentication settings ======================= Use the following settings to authenticate with AliCloud OSS. .. code-block:: bash # AliCloud access key ID OSS_ACCESS_KEY_ID = # AliCloud access key secret OSS_ACCESS_KEY_SECRET = Storage settings ======================= For public or public-read buckets, storage urls will be bucket_name.endpoint/key format For private buckets, storage urls will be signed url. The expires time can be set by OSS_EXPIRE_TIME as environment variable or as Django settings. The default value for OSS_EXPIRE_TIME is 30 days. .. code-block:: bash OSS_EXPIRE_TIME = Bucket CDN settings ===================== 设置对应bucket的cdn地址(仅支持非私有的bucket): .. code-block:: bash OSS_BUCKET_CDN = 'http://xxx.xxx.xx' 重名文件覆盖设置 ==================== 针对重名文件的处理方式,如果为True,表示覆盖;为False表示文件名称+时间戳 .. code-block:: bash OSS_COVERAGE_IF_FILE_EXIST = False File storage settings ===================== Use the following settings to configure AliCloud OSS file storage. .. code-block:: bash # The name of the bucket to store files in OSS_BUCKET_NAME = # The URL of AliCloud OSS endpoint # Refer https://www.alibabacloud.com/help/zh/doc-detail/31837.htm for OSS Region & Endpoint OSS_ENDPOINT = # The default location for your files MEDIA_URL = '/media/' 文件存储格式设置 =========================== 设置上传后的文件存储到数据库中使用何种方式,为False表示存储为xxx.png, 为True表示存储为http:///xxx.png .. code-block:: bash OSS_FILE_SAVE_AS_URL = Staticfiles storage settings ============================ All of the file storage settings are available for the staticfiles storage. .. code-block:: bash # The default location for your static files STATIC_URL = '/static/' staticfiles provides command 'collectstatic'. Run following command to collect all sub-folder 'static' of each app and upload to STATIC_URL. .. code-block:: bash $ python manage.py collectstatic Testing ======= First set the required AccessKeyId, AccessKeySecret, endpoint and bucket information for the test through environment variables (**Do not use the bucket for the production environment**). Take the Linux system for example: .. code-block:: bash $ export OSS_ACCESS_KEY_ID= $ export OSS_ACCESS_KEY_SECRET= $ export OSS_BUCKET_NAME= $ export OSS_ENDPOINT= Support and announcements ========================= Downloads and bug tracking can be found at the `main project website `_. License ======= - `MIT `_.