Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 106 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
.venv/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.vscode/settings.json
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# django-oss-storage changelog

## 1.0.0

- First production release
- Testing against Django 1.11

## 2.0.0

- Set OSS storage location based on STATIC_ROOT and MEDIA_ROOT, other than STATIC_URL and MEDIA_URL
- Add support for Django 5.1+
9 changes: 0 additions & 9 deletions CHANGELOG.rst

This file was deleted.

2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
include LICENSE README.rst CHANGELOG.rst
include LICENSE README.md CHANGELOG.md
recursive-include tests *.py
166 changes: 166 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
# Django AliCloud OSS Storage V2

**django-oss-storage-v2** provides a Django AliCloud OSS file storage,
compatible with Django 5.1+.

## Features

- Django file storage for AliCloud OSS
- Django static file storage for AliCloud OSS
- Works in Python 2 & 3
- Supports Django 5.1+

## Installation

``` bash
$ pip install django-oss-storage-v2
```

## for Django < 5.1

- 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).

### Storage settings

Use the following settings for file storage.

``` bash
STATICFILES_STORAGE = 'django_oss_storage.backends.OssStaticStorage'

DEFAULT_FILE_STORAGE = 'django_oss_storage.backends.OssMediaStorage'
```

### Authentication settings

Use the following settings to authenticate with AliCloud OSS.

``` bash
# AliCloud access key ID
OSS_ACCESS_KEY_ID = <Your Access Key ID>

# AliCloud access key secret
OSS_ACCESS_KEY_SECRET = <Your Access Key Secret>
```

### OSS 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.

``` bash
OSS_EXPIRE_TIME = <Expire Time in Seconds>

# The name of the bucket to store files in
OSS_BUCKET_NAME = <Your 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 = <Your access endpoint>

```

## for Django >= 5.1

- Add `'django_oss_storage'` to your `INSTALLED_APPS` setting
- Set your `STORAGE` setting as below.

``` bash
STORAGES = {
"default": {
"BACKEND": "django_oss_storage.backends.OssMediaStorage",
"OPTIONS": {
"access_key_id": <Your Access Key ID>,
"access_key_secret": <Your Access Key Secret>,
"bucket_name": <Your bucket name>,
"endpoint": <Your access endpoint>,
"expire_time": <Expire Time in Seconds>,
}
},
"staticfiles": {
"BACKEND": "django_oss_storage.backends.OssStaticStorage",
"OPTIONS": {
"access_key_id": <Your Access Key ID>,
"access_key_secret": <Your Access Key Secret>,
"bucket_name": <Your bucket name>,
"endpoint": <Your access endpoint>,
"expire_time": <Expire Time in Seconds>,
}
}
}
```


## File storage settings

Use the following settings to configure AliCloud OSS file storage.

``` bash
# The default location for your project
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

# The default location for your media files
# In both cases, your media files will be put into OSS://<your_bucket>/media/
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_ROOT = "/media/"

# Your can use this MEDIA_URL in your django templates
MEDIA_URL = "http://<your-bucket>.<your-endpoint>.aliyuncs.com/media/"
# Or your custom domain MEDIA_URL
MEDIA_URL = "http://<your-custom-domain>/media/"
```

## Staticfiles storage settings

All of the file storage settings are available for the staticfiles
storage.

``` bash
# The default location for your static files
# In both case, your static files will be put into OSS://<your_bucket>/static/
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATIC_ROOT = "/static/"

# Your can use this STATIC_URL in your django templates
STATIC_URL = 'http://<your-bucket>.<your-endpoint>.aliyuncs.com/static/'
# Or your custom domain STATIC_URL
STATIC_URL = "http://<your-custom-domain>/static/"
```

staticfiles provides command \'collectstatic\'. Run following command to
collect all sub-folder \'static\' of each app and upload to STATIC_URL.

``` 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:

``` bash
$ export OSS_ACCESS_KEY_ID=<AccessKeyId>
$ export OSS_ACCESS_KEY_SECRET=<AccessKeySecret>
$ export OSS_BUCKET_NAME=<bucket>
$ export OSS_ENDPOINT=<endpoint>
```

## Support and announcements

Downloads and bug tracking can be found at the [main project
website](http://github.com/twisker/django-oss-storage).

## License

- [MIT](https://github.com/twisker/django-oss-storage/blob/master/LICENSE).
Loading