# Django REST File Manager
A package that provides authenticated file management (upload/download) using REST Framework and Amazon S3 (optionally)
Install app:
````bash
pip install djangorestfilemanager
````
Add in installed apps:
````python
INSTALLED_APPS = [..., 'rest_framework', 'django_filters', 'djangorestfilemanager.apps.DjangoRestFileManagerConfig']
````
/proyect/settings.py
Specific app settings, by default will save in /files/....
````python
REST_FILE_MANAGER = {
'UPLOADS_DIR': '...'
}
````
S3 storage setup.
If AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY and AWS_STORAGE_BUCKET_NAME is not provided, files will save in local storage
```python
STATIC_URL = '/static/'
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media', 'files')
S3_STORAGE = False
AWS_DEFAULT_ACL = None
if env('AWS_ACCESS_KEY_ID') and env('AWS_SECRET_ACCESS_KEY') and env(
'AWS_STORAGE_BUCKET_NAME'):
S3_STORAGE = True
AWS_ACCESS_KEY_ID = env('AWS_ACCESS_KEY_ID')
AWS_SECRET_ACCESS_KEY = env('AWS_SECRET_ACCESS_KEY')
AWS_STORAGE_BUCKET_NAME = env('AWS_STORAGE_BUCKET_NAME')
AWS_LOCATION = 'media'
AWS_S3_CUSTOM_DOMAIN = f'{AWS_STORAGE_BUCKET_NAME}.s3.amazonaws.com'
AWS_S3_OBJECT_PARAMETERS = {'CacheControl': 'max-age=86400'}
AWS_S3_FILE_OVERWRITE = False
AWS_S3_ENCRYPTION = True
AWS_IS_GZIPPED = True
GZIP_CONTENT_TYPES = (
'application/pdf', 'application/json', 'text/csv', 'application/xml', 'application/xhtml+xml',
'application/msword', 'application/vnd.oasis.opendocument.presentation',
'application/vnd.oasis.opendocument.spreadsheet', 'application/vnd.oasis.opendocument.text',
'application/vnd.ms-powerpoint', 'application/x-rar-compressed', 'application/xhtml+xml',
'application/vnd.ms-excel', 'application/xml', 'application/zip',
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
)
```
.env:
```.env
AWS_DEFAULT_ACL=''
AWS_ACCESS_KEY_ID=''
AWS_SECRET_ACCESS_KEY=''
AWS_STORAGE_BUCKET_NAME=''
AWS_CACHE_CONTROL=86400
AWS_LOCATION=''
AWS_S3_FILE_OVERWRITE=False
```
urls.py
```python
from djangorestfilemanager.urls import router as file_manager_router
urlpatterns = [
...,
path('', include(file_manager_router.urls))
]
```
#API REST ENDPOINTS:
Permission: Authentication is required.
If user is superuser, can download all files.
If user is file owner, that user can download this file.
If file is shared (share==True) and user have perms, can download this file.
Upload File
| param | description |
| ------- | ----------- |
| url | /{{api}}/files/ |
| methods | post |
| --- | --- |
| file | file object |
| type | string, max length 10 not required |
| permission | string content_type.model +.+ permission.name Example: user.can_create_user, default '' |
| share | bool, default true |
| data | jsonfield |
| --- | --- |
| return_data | uuid |
Download File
| param | description |
| ----- | ----------- |
| url | /{{api}}/files/{{uuid}}/ |
| --- | --- |
| methods | get |
| --- | --- |
| return | download file. |
#OVERRIDE ENDPOINTS
```python
DJANGO_REST_FILE_MANAGER_SERIALIZERS = {
'FILE_SERIALIZER': '...',
'FILE_VIEW_SERIALIZER': '...',
}
```
#OVERRIDE SETTINGS
```
REST_FILE_MANAGER = {
'UPLOADS_DIR': os.environ.get('UPLOADS_DIR', default='media/'),
'STATUS_CHOICES': (
(PENDING, 'Pending'),
....
)
'DEFAULT_CHOICE':'' #STRING VALUE,
'DEFAULT_SHAREABLE': Boolean, default True
}
```
# How to update to Pypi
When a new release is ready we have to make the package. Exec the following command (Remember to update setup.py with the current version of the package.)
```
python setup.py sdist
```
After that, we have to push our package to Pypi with `twine` (the first time we will have to install it)
```
twine upload dist/*
```
This command will upload every version existing on dist folder, we can specify one changing `dist/*` to the new dist file `dist/package_filename.gz`.
Raw data
{
"_id": null,
"home_page": "https://gitlab.com/kas-factory/packages/django-rest-file-manager",
"name": "djangorestfilemanager",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "",
"author": "Avelino @ KF",
"author_email": "avelino@kasfactory.net",
"download_url": "https://files.pythonhosted.org/packages/55/78/c15f89ac2c4ac2ebcc26b3015cc86793f21defc39cc47b9b7d588b584ce0/djangorestfilemanager-2.0.2.tar.gz",
"platform": null,
"description": "# Django REST File Manager\n\nA package that provides authenticated file management (upload/download) using REST Framework and Amazon S3 (optionally)\n\nInstall app:\n\n````bash\npip install djangorestfilemanager\n````\n\nAdd in installed apps:\n\n````python\nINSTALLED_APPS = [..., 'rest_framework', 'django_filters', 'djangorestfilemanager.apps.DjangoRestFileManagerConfig']\n\n````\n\n/proyect/settings.py\n\nSpecific app settings, by default will save in /files/.... \n````python\nREST_FILE_MANAGER = {\n 'UPLOADS_DIR': '...'\n}\n````\n\nS3 storage setup. \n\nIf AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY and AWS_STORAGE_BUCKET_NAME is not provided, files will save in local storage\n```python\nSTATIC_URL = '/static/'\nMEDIA_URL = '/media/'\nMEDIA_ROOT = os.path.join(BASE_DIR, 'media', 'files')\n\nS3_STORAGE = False\nAWS_DEFAULT_ACL = None\n\nif env('AWS_ACCESS_KEY_ID') and env('AWS_SECRET_ACCESS_KEY') and env(\n 'AWS_STORAGE_BUCKET_NAME'):\n S3_STORAGE = True\n AWS_ACCESS_KEY_ID = env('AWS_ACCESS_KEY_ID')\n AWS_SECRET_ACCESS_KEY = env('AWS_SECRET_ACCESS_KEY')\n AWS_STORAGE_BUCKET_NAME = env('AWS_STORAGE_BUCKET_NAME')\n AWS_LOCATION = 'media'\n AWS_S3_CUSTOM_DOMAIN = f'{AWS_STORAGE_BUCKET_NAME}.s3.amazonaws.com'\n AWS_S3_OBJECT_PARAMETERS = {'CacheControl': 'max-age=86400'}\n AWS_S3_FILE_OVERWRITE = False\n AWS_S3_ENCRYPTION = True\n AWS_IS_GZIPPED = True\n GZIP_CONTENT_TYPES = (\n 'application/pdf', 'application/json', 'text/csv', 'application/xml', 'application/xhtml+xml',\n 'application/msword', 'application/vnd.oasis.opendocument.presentation',\n 'application/vnd.oasis.opendocument.spreadsheet', 'application/vnd.oasis.opendocument.text',\n 'application/vnd.ms-powerpoint', 'application/x-rar-compressed', 'application/xhtml+xml',\n 'application/vnd.ms-excel', 'application/xml', 'application/zip',\n 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',\n 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'\n )\n```\n\n \n\n.env:\n\n```.env\nAWS_DEFAULT_ACL=''\nAWS_ACCESS_KEY_ID=''\nAWS_SECRET_ACCESS_KEY=''\nAWS_STORAGE_BUCKET_NAME=''\nAWS_CACHE_CONTROL=86400\nAWS_LOCATION=''\nAWS_S3_FILE_OVERWRITE=False\n```\n\nurls.py\n\n\n```python\nfrom djangorestfilemanager.urls import router as file_manager_router\n\nurlpatterns = [\n ...,\n path('', include(file_manager_router.urls))\n\n]\n```\n\n#API REST ENDPOINTS:\n\nPermission: Authentication is required. \n\nIf user is superuser, can download all files.\n\nIf user is file owner, that user can download this file.\n\nIf file is shared (share==True) and user have perms, can download this file. \n\n\nUpload File\n\n| param | description |\n| ------- | ----------- |\n| url | /{{api}}/files/ | \n| methods | post |\n| --- | --- |\n| file | file object |\n| type | string, max length 10 not required |\n| permission | string content_type.model +.+ permission.name Example: user.can_create_user, default '' |\n| share | bool, default true |\n| data | jsonfield |\n| --- | --- |\n| return_data | uuid |\n\n\nDownload File\n\n| param | description |\n| ----- | ----------- |\n| url | /{{api}}/files/{{uuid}}/ |\n| --- | --- |\n| methods | get |\n| --- | --- |\n| return | download file. |\n\n\n#OVERRIDE ENDPOINTS\n```python\nDJANGO_REST_FILE_MANAGER_SERIALIZERS = {\n 'FILE_SERIALIZER': '...',\n 'FILE_VIEW_SERIALIZER': '...',\n}\n```\n#OVERRIDE SETTINGS\n```\nREST_FILE_MANAGER = {\n 'UPLOADS_DIR': os.environ.get('UPLOADS_DIR', default='media/'),\n 'STATUS_CHOICES': (\n (PENDING, 'Pending'),\n ....\n )\n 'DEFAULT_CHOICE':'' #STRING VALUE,\n 'DEFAULT_SHAREABLE': Boolean, default True\n}\n```\n# How to update to Pypi\n\nWhen a new release is ready we have to make the package. Exec the following command (Remember to update setup.py with the current version of the package.)\n\n```\npython setup.py sdist\n```\n\nAfter that, we have to push our package to Pypi with `twine` (the first time we will have to install it)\n\n```\ntwine upload dist/*\n```\n\nThis command will upload every version existing on dist folder, we can specify one changing `dist/*` to the new dist file `dist/package_filename.gz`. \n\n\n\n\n",
"bugtrack_url": null,
"license": "COPYRIGHT",
"summary": "Django REST File Manager.",
"version": "2.0.2",
"project_urls": {
"Homepage": "https://gitlab.com/kas-factory/packages/django-rest-file-manager"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "5578c15f89ac2c4ac2ebcc26b3015cc86793f21defc39cc47b9b7d588b584ce0",
"md5": "89b67e3af9b76b7da67cfe96265e6480",
"sha256": "770f0c5bc805e8a62313a9ced374dbe5637cf57eccc3d46378065c33c4850c95"
},
"downloads": -1,
"filename": "djangorestfilemanager-2.0.2.tar.gz",
"has_sig": false,
"md5_digest": "89b67e3af9b76b7da67cfe96265e6480",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 11572,
"upload_time": "2023-05-16T09:53:13",
"upload_time_iso_8601": "2023-05-16T09:53:13.875841Z",
"url": "https://files.pythonhosted.org/packages/55/78/c15f89ac2c4ac2ebcc26b3015cc86793f21defc39cc47b9b7d588b584ce0/djangorestfilemanager-2.0.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-05-16 09:53:13",
"github": false,
"gitlab": true,
"bitbucket": false,
"codeberg": false,
"gitlab_user": "kas-factory",
"gitlab_project": "packages",
"lcname": "djangorestfilemanager"
}