├── Dockerfile ├── LICENSE ├── README.md ├── core ├── __init__.py ├── __pycache__ │ ├── __init__.cpython-37.pyc │ ├── __init__.cpython-39.pyc │ ├── admin.cpython-37.pyc │ ├── admin.cpython-39.pyc │ ├── apps.cpython-37.pyc │ ├── apps.cpython-39.pyc │ ├── models.cpython-37.pyc │ ├── models.cpython-39.pyc │ ├── serializer.cpython-37.pyc │ ├── serializer.cpython-39.pyc │ ├── serializers.cpython-37.pyc │ ├── serializers.cpython-39.pyc │ ├── tests.cpython-39.pyc │ ├── urls.cpython-37.pyc │ ├── urls.cpython-39.pyc │ ├── views.cpython-37.pyc │ └── views.cpython-39.pyc ├── admin.py ├── apps.py ├── migrations │ ├── 0001_initial.py │ ├── 0002_remove_uploadedfile_file_url_uploadedfile_file.py │ ├── 0003_alter_uploadedfile_file.py │ ├── 0004_remove_uploadedfile_file_uploadedfile_file_url_and_more.py │ ├── 0005_remove_uploadedfile_file_url_uploadedfile_file_and_more.py │ ├── __init__.py │ └── __pycache__ │ │ ├── 0001_initial.cpython-39.pyc │ │ ├── 0002_remove_uploadedfile_file_url_uploadedfile_file.cpython-39.pyc │ │ ├── 0003_alter_uploadedfile_file.cpython-39.pyc │ │ ├── 0004_remove_uploadedfile_file_uploadedfile_file_url_and_more.cpython-39.pyc │ │ ├── 0005_remove_uploadedfile_file_url_uploadedfile_file_and_more.cpython-39.pyc │ │ └── __init__.cpython-39.pyc ├── models.py ├── serializers.py ├── tests.py ├── urls.py └── views.py ├── db.sqlite3 ├── djangoMINIO ├── __init__.py ├── __pycache__ │ ├── __init__.cpython-37.pyc │ ├── __init__.cpython-39.pyc │ ├── settings.cpython-37.pyc │ ├── settings.cpython-39.pyc │ ├── urls.cpython-37.pyc │ ├── urls.cpython-39.pyc │ ├── wsgi.cpython-37.pyc │ └── wsgi.cpython-39.pyc ├── asgi.py ├── settings.py ├── urls.py └── wsgi.py ├── docker-compose.yml ├── manage.py ├── requirements.txt ├── test └── test.txt /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM python:3.9-alpine 2 | 3 | ENV PYTHONUNBUFFERED=1 4 | 5 | RUN mkdir /app 6 | COPY . /app 7 | 8 | WORKDIR /app 9 | 10 | RUN pip install --upgrade pip 11 | 12 | RUN apk update 13 | 14 | COPY ./requirements.txt /app 15 | 16 | RUN pip install -r requirements.txt 17 | 18 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Mazdak Pakaghideh 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Django MINIO 2 | 3 | This is a django project for communicating and uploading files to Minio service using **django DRF** 4 | 5 | - - - - 6 | 7 | # Tools Used to develope this script🎯 8 | 9 | ![Python](https://img.shields.io/badge/Python-3776AB?style=for-the-badge&logo=python&logoColor=white) 10 | ![git](https://img.shields.io/badge/Git-F05032?style=for-the-badge&logo=git&logoColor=white) 11 | ![macos](https://img.shields.io/badge/mac%20os-000000?style=for-the-badge&logo=apple&logoColor=white) 12 | ![appple](https://img.shields.io/badge/Apple-laptop-999999?style=for-the-badge&logo=apple&logoColor=white) 13 | ![vscode](https://img.shields.io/badge/Visual_Studio_Code-0078D4?style=for-the-badge&logo=visual%20studio%20code&logoColor=white) 14 | 15 | 16 | 17 | - - - - 18 | # Runing 19 | 20 | 1/2 install docker & docker-composer 21 | 22 | $ brew install docker | apt-get install docker-compose 23 | 24 | 25 | 26 | 2/2 Run the script 27 | 28 | $ docker compose up --build 29 | 30 | 31 | 32 | # Contributions : 33 | 34 | Feel free to give your opinion and show my issues for my improvement 35 | -------------------------------------------------------------------------------- /core/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mazdakdev/Django-MINIO/ed4a420ed7d3e471caba07c29e235c48618e890c/core/__init__.py -------------------------------------------------------------------------------- /core/__pycache__/__init__.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mazdakdev/Django-MINIO/ed4a420ed7d3e471caba07c29e235c48618e890c/core/__pycache__/__init__.cpython-37.pyc -------------------------------------------------------------------------------- /core/__pycache__/__init__.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mazdakdev/Django-MINIO/ed4a420ed7d3e471caba07c29e235c48618e890c/core/__pycache__/__init__.cpython-39.pyc -------------------------------------------------------------------------------- /core/__pycache__/admin.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mazdakdev/Django-MINIO/ed4a420ed7d3e471caba07c29e235c48618e890c/core/__pycache__/admin.cpython-37.pyc -------------------------------------------------------------------------------- /core/__pycache__/admin.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mazdakdev/Django-MINIO/ed4a420ed7d3e471caba07c29e235c48618e890c/core/__pycache__/admin.cpython-39.pyc -------------------------------------------------------------------------------- /core/__pycache__/apps.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mazdakdev/Django-MINIO/ed4a420ed7d3e471caba07c29e235c48618e890c/core/__pycache__/apps.cpython-37.pyc -------------------------------------------------------------------------------- /core/__pycache__/apps.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mazdakdev/Django-MINIO/ed4a420ed7d3e471caba07c29e235c48618e890c/core/__pycache__/apps.cpython-39.pyc -------------------------------------------------------------------------------- /core/__pycache__/models.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mazdakdev/Django-MINIO/ed4a420ed7d3e471caba07c29e235c48618e890c/core/__pycache__/models.cpython-37.pyc -------------------------------------------------------------------------------- /core/__pycache__/models.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mazdakdev/Django-MINIO/ed4a420ed7d3e471caba07c29e235c48618e890c/core/__pycache__/models.cpython-39.pyc -------------------------------------------------------------------------------- /core/__pycache__/serializer.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mazdakdev/Django-MINIO/ed4a420ed7d3e471caba07c29e235c48618e890c/core/__pycache__/serializer.cpython-37.pyc -------------------------------------------------------------------------------- /core/__pycache__/serializer.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mazdakdev/Django-MINIO/ed4a420ed7d3e471caba07c29e235c48618e890c/core/__pycache__/serializer.cpython-39.pyc -------------------------------------------------------------------------------- /core/__pycache__/serializers.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mazdakdev/Django-MINIO/ed4a420ed7d3e471caba07c29e235c48618e890c/core/__pycache__/serializers.cpython-37.pyc -------------------------------------------------------------------------------- /core/__pycache__/serializers.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mazdakdev/Django-MINIO/ed4a420ed7d3e471caba07c29e235c48618e890c/core/__pycache__/serializers.cpython-39.pyc -------------------------------------------------------------------------------- /core/__pycache__/tests.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mazdakdev/Django-MINIO/ed4a420ed7d3e471caba07c29e235c48618e890c/core/__pycache__/tests.cpython-39.pyc -------------------------------------------------------------------------------- /core/__pycache__/urls.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mazdakdev/Django-MINIO/ed4a420ed7d3e471caba07c29e235c48618e890c/core/__pycache__/urls.cpython-37.pyc -------------------------------------------------------------------------------- /core/__pycache__/urls.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mazdakdev/Django-MINIO/ed4a420ed7d3e471caba07c29e235c48618e890c/core/__pycache__/urls.cpython-39.pyc -------------------------------------------------------------------------------- /core/__pycache__/views.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mazdakdev/Django-MINIO/ed4a420ed7d3e471caba07c29e235c48618e890c/core/__pycache__/views.cpython-37.pyc -------------------------------------------------------------------------------- /core/__pycache__/views.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mazdakdev/Django-MINIO/ed4a420ed7d3e471caba07c29e235c48618e890c/core/__pycache__/views.cpython-39.pyc -------------------------------------------------------------------------------- /core/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | from .models import UploadedFile 3 | # Register your models here. 4 | 5 | admin.site.register(UploadedFile) -------------------------------------------------------------------------------- /core/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class CoreConfig(AppConfig): 5 | default_auto_field = 'django.db.models.BigAutoField' 6 | name = 'core' 7 | -------------------------------------------------------------------------------- /core/migrations/0001_initial.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 4.0.2 on 2022-02-12 10:44 2 | 3 | from django.conf import settings 4 | from django.db import migrations, models 5 | import django.db.models.fields.related 6 | 7 | 8 | class Migration(migrations.Migration): 9 | 10 | initial = True 11 | 12 | dependencies = [ 13 | migrations.swappable_dependency(settings.AUTH_USER_MODEL), 14 | ] 15 | 16 | operations = [ 17 | migrations.CreateModel( 18 | name='UploadedFile', 19 | fields=[ 20 | ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 21 | ('type', models.CharField(max_length=5)), 22 | ('size', models.BigIntegerField()), 23 | ('file_url', models.CharField(max_length=300)), 24 | ('user', models.ForeignKey(on_delete=django.db.models.fields.related.ForeignKey, to=settings.AUTH_USER_MODEL)), 25 | ], 26 | ), 27 | ] 28 | -------------------------------------------------------------------------------- /core/migrations/0002_remove_uploadedfile_file_url_uploadedfile_file.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 4.0.2 on 2022-02-12 11:03 2 | 3 | from django.db import migrations, models 4 | 5 | 6 | class Migration(migrations.Migration): 7 | 8 | dependencies = [ 9 | ('core', '0001_initial'), 10 | ] 11 | 12 | operations = [ 13 | migrations.RemoveField( 14 | model_name='uploadedfile', 15 | name='file_url', 16 | ), 17 | migrations.AddField( 18 | model_name='uploadedfile', 19 | name='file', 20 | field=models.FileField(default='d', upload_to=''), 21 | preserve_default=False, 22 | ), 23 | ] 24 | -------------------------------------------------------------------------------- /core/migrations/0003_alter_uploadedfile_file.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 4.0.2 on 2022-02-12 11:22 2 | 3 | from django.db import migrations, models 4 | 5 | 6 | class Migration(migrations.Migration): 7 | 8 | dependencies = [ 9 | ('core', '0002_remove_uploadedfile_file_url_uploadedfile_file'), 10 | ] 11 | 12 | operations = [ 13 | migrations.AlterField( 14 | model_name='uploadedfile', 15 | name='file', 16 | field=models.FileField(upload_to='sdds/dssds/'), 17 | ), 18 | ] 19 | -------------------------------------------------------------------------------- /core/migrations/0004_remove_uploadedfile_file_uploadedfile_file_url_and_more.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 4.0.2 on 2022-02-12 12:48 2 | 3 | from django.db import migrations, models 4 | 5 | 6 | class Migration(migrations.Migration): 7 | 8 | dependencies = [ 9 | ('core', '0003_alter_uploadedfile_file'), 10 | ] 11 | 12 | operations = [ 13 | migrations.RemoveField( 14 | model_name='uploadedfile', 15 | name='file', 16 | ), 17 | migrations.AddField( 18 | model_name='uploadedfile', 19 | name='file_url', 20 | field=models.CharField(default='sd', max_length=300), 21 | preserve_default=False, 22 | ), 23 | migrations.AlterField( 24 | model_name='uploadedfile', 25 | name='type', 26 | field=models.CharField(max_length=4), 27 | ), 28 | ] 29 | -------------------------------------------------------------------------------- /core/migrations/0005_remove_uploadedfile_file_url_uploadedfile_file_and_more.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 4.0.2 on 2022-02-12 12:49 2 | 3 | from django.db import migrations, models 4 | 5 | 6 | class Migration(migrations.Migration): 7 | 8 | dependencies = [ 9 | ('core', '0004_remove_uploadedfile_file_uploadedfile_file_url_and_more'), 10 | ] 11 | 12 | operations = [ 13 | migrations.RemoveField( 14 | model_name='uploadedfile', 15 | name='file_url', 16 | ), 17 | migrations.AddField( 18 | model_name='uploadedfile', 19 | name='file', 20 | field=models.FileField(default='sd', upload_to='files/'), 21 | preserve_default=False, 22 | ), 23 | migrations.AlterField( 24 | model_name='uploadedfile', 25 | name='type', 26 | field=models.CharField(max_length=5), 27 | ), 28 | ] 29 | -------------------------------------------------------------------------------- /core/migrations/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mazdakdev/Django-MINIO/ed4a420ed7d3e471caba07c29e235c48618e890c/core/migrations/__init__.py -------------------------------------------------------------------------------- /core/migrations/__pycache__/0001_initial.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mazdakdev/Django-MINIO/ed4a420ed7d3e471caba07c29e235c48618e890c/core/migrations/__pycache__/0001_initial.cpython-39.pyc -------------------------------------------------------------------------------- /core/migrations/__pycache__/0002_remove_uploadedfile_file_url_uploadedfile_file.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mazdakdev/Django-MINIO/ed4a420ed7d3e471caba07c29e235c48618e890c/core/migrations/__pycache__/0002_remove_uploadedfile_file_url_uploadedfile_file.cpython-39.pyc -------------------------------------------------------------------------------- /core/migrations/__pycache__/0003_alter_uploadedfile_file.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mazdakdev/Django-MINIO/ed4a420ed7d3e471caba07c29e235c48618e890c/core/migrations/__pycache__/0003_alter_uploadedfile_file.cpython-39.pyc -------------------------------------------------------------------------------- /core/migrations/__pycache__/0004_remove_uploadedfile_file_uploadedfile_file_url_and_more.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mazdakdev/Django-MINIO/ed4a420ed7d3e471caba07c29e235c48618e890c/core/migrations/__pycache__/0004_remove_uploadedfile_file_uploadedfile_file_url_and_more.cpython-39.pyc -------------------------------------------------------------------------------- /core/migrations/__pycache__/0005_remove_uploadedfile_file_url_uploadedfile_file_and_more.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mazdakdev/Django-MINIO/ed4a420ed7d3e471caba07c29e235c48618e890c/core/migrations/__pycache__/0005_remove_uploadedfile_file_url_uploadedfile_file_and_more.cpython-39.pyc -------------------------------------------------------------------------------- /core/migrations/__pycache__/__init__.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mazdakdev/Django-MINIO/ed4a420ed7d3e471caba07c29e235c48618e890c/core/migrations/__pycache__/__init__.cpython-39.pyc -------------------------------------------------------------------------------- /core/models.py: -------------------------------------------------------------------------------- 1 | from django.db import models 2 | from django.contrib.auth.models import User 3 | from django_minio_backend import MinioBackend, iso_date_prefix 4 | 5 | class UploadedFile(models.Model): 6 | user = models.ForeignKey(User , on_delete=models.ForeignKey) 7 | type = models.CharField(max_length=5) 8 | size = models.BigIntegerField() 9 | file = models.FileField(storage=MinioBackend(bucket_name='test'), upload_to=iso_date_prefix) 10 | 11 | -------------------------------------------------------------------------------- /core/serializers.py: -------------------------------------------------------------------------------- 1 | from rest_framework.serializers import ModelSerializer 2 | from .models import UploadedFile 3 | 4 | class UploadedFileSerializer(ModelSerializer): 5 | class Meta: 6 | model = UploadedFile 7 | fields = ("id" , "user_id" , "file" , "size" , "type" ) 8 | 9 | def __init__(self, *args, **kwargs): 10 | super(UploadedFileSerializer, self).__init__(*args, **kwargs) 11 | self.fields['size'].required = False 12 | self.fields['type'].required = False 13 | 14 | 15 | -------------------------------------------------------------------------------- /core/tests.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | from django.http import response 3 | from django.urls import reverse 4 | from rest_framework.test import APITestCase 5 | from rest_framework_simplejwt.tokens import RefreshToken 6 | from rest_framework import status 7 | from .serializers import * 8 | import json 9 | from django.contrib.auth.models import User 10 | from django.core.files.uploadedfile import SimpleUploadedFile 11 | from rest_framework.test import APIClient 12 | from django_minio_backend import MinioBackend 13 | 14 | 15 | class FilesTestCase(APITestCase): 16 | def setUp(self): 17 | user = User.objects.create_user("someuser","1234pass") 18 | self.token = RefreshToken.for_user(user).access_token 19 | 20 | 21 | def test_read_files(self): 22 | token = self.token 23 | video = SimpleUploadedFile("file.mp4", b"file_content", content_type="video/mp4") 24 | response = self.client.post(reverse("upload") , {'file':video} , format="multipart" , **{'HTTP_AUTHORIZATION': f'Bearer {token}'}) 25 | self.assertEqual(response.status_code , status.HTTP_201_CREATED) 26 | 27 | response = self.client.get(reverse("upload") , **{'HTTP_AUTHORIZATION': f'Bearer {token}'}) 28 | id = json.loads(response.content)[0]["id"] 29 | self.assertEqual( id , 1 ) 30 | 31 | def test_delete_file(self): 32 | token = self.token 33 | video = SimpleUploadedFile("file.mp4", b"file_content", content_type="video/mp4") 34 | response = self.client.post(reverse("upload") , {'file':video} , format="multipart" , **{'HTTP_AUTHORIZATION': f'Bearer {token}'}) 35 | self.assertEqual(response.status_code , status.HTTP_201_CREATED) 36 | 37 | del_response = self.client.delete("/api/upload/1" , **{'HTTP_AUTHORIZATION': f'Bearer {token}'}) 38 | self.assertEqual(del_response.status_code , status.HTTP_200_OK) 39 | 40 | class MinioTestCase(TestCase): 41 | 42 | def test_minio_is_availabe(self): 43 | minio_available = MinioBackend().is_minio_available() # An empty string is fine this time 44 | self.assertTrue(minio_available) 45 | -------------------------------------------------------------------------------- /core/urls.py: -------------------------------------------------------------------------------- 1 | 2 | from django.urls import path , include 3 | from . import views 4 | 5 | urlpatterns = [ 6 | path('upload/' , views.upload_or_get , name="upload" ), 7 | path('upload/' , views.delete_file , name="delete"), 8 | ] -------------------------------------------------------------------------------- /core/views.py: -------------------------------------------------------------------------------- 1 | from django.http import HttpResponse 2 | from core.serializers import UploadedFileSerializer 3 | from rest_framework import status 4 | from .serializers import * 5 | from .models import * 6 | from rest_framework.decorators import api_view , permission_classes 7 | from rest_framework.response import Response 8 | from rest_framework import permissions 9 | from django.contrib.auth.models import User 10 | 11 | 12 | 13 | @api_view(['POST' , 'GET']) 14 | @permission_classes([permissions.IsAuthenticated]) 15 | def upload_or_get(request): 16 | if request.method == 'POST': 17 | serializer = UploadedFileSerializer(data=request.data) 18 | #upload file to MINIO 19 | if serializer.is_valid(): 20 | file = serializer.validated_data["file"] 21 | 22 | # get the format of file 23 | type = str(file).split(".")[1] 24 | 25 | serializer.save(user_id=request.user.id , size=file.size , type=type) 26 | return Response(serializer.data , status.HTTP_201_CREATED) 27 | return Response(serializer.errors , status=status.HTTP_400_BAD_REQUEST) 28 | 29 | elif request.method == "GET": 30 | files = UploadedFile.objects.filter(user=request.user) 31 | serializer = UploadedFileSerializer(files , many=True) 32 | return Response(serializer.data) 33 | 34 | return Response("Something Went Wrong" , status=status.HTTP_400_BAD_REQUEST) 35 | 36 | 37 | @api_view(['DELETE']) 38 | @permission_classes([permissions.IsAuthenticated]) 39 | def delete_file(request , id): 40 | if request.method == 'DELETE': 41 | file = UploadedFile.objects.get(id=id) 42 | file.delete() 43 | return Response("Deleted successfully ! " ) -------------------------------------------------------------------------------- /db.sqlite3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mazdakdev/Django-MINIO/ed4a420ed7d3e471caba07c29e235c48618e890c/db.sqlite3 -------------------------------------------------------------------------------- /djangoMINIO/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mazdakdev/Django-MINIO/ed4a420ed7d3e471caba07c29e235c48618e890c/djangoMINIO/__init__.py -------------------------------------------------------------------------------- /djangoMINIO/__pycache__/__init__.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mazdakdev/Django-MINIO/ed4a420ed7d3e471caba07c29e235c48618e890c/djangoMINIO/__pycache__/__init__.cpython-37.pyc -------------------------------------------------------------------------------- /djangoMINIO/__pycache__/__init__.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mazdakdev/Django-MINIO/ed4a420ed7d3e471caba07c29e235c48618e890c/djangoMINIO/__pycache__/__init__.cpython-39.pyc -------------------------------------------------------------------------------- /djangoMINIO/__pycache__/settings.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mazdakdev/Django-MINIO/ed4a420ed7d3e471caba07c29e235c48618e890c/djangoMINIO/__pycache__/settings.cpython-37.pyc -------------------------------------------------------------------------------- /djangoMINIO/__pycache__/settings.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mazdakdev/Django-MINIO/ed4a420ed7d3e471caba07c29e235c48618e890c/djangoMINIO/__pycache__/settings.cpython-39.pyc -------------------------------------------------------------------------------- /djangoMINIO/__pycache__/urls.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mazdakdev/Django-MINIO/ed4a420ed7d3e471caba07c29e235c48618e890c/djangoMINIO/__pycache__/urls.cpython-37.pyc -------------------------------------------------------------------------------- /djangoMINIO/__pycache__/urls.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mazdakdev/Django-MINIO/ed4a420ed7d3e471caba07c29e235c48618e890c/djangoMINIO/__pycache__/urls.cpython-39.pyc -------------------------------------------------------------------------------- /djangoMINIO/__pycache__/wsgi.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mazdakdev/Django-MINIO/ed4a420ed7d3e471caba07c29e235c48618e890c/djangoMINIO/__pycache__/wsgi.cpython-37.pyc -------------------------------------------------------------------------------- /djangoMINIO/__pycache__/wsgi.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mazdakdev/Django-MINIO/ed4a420ed7d3e471caba07c29e235c48618e890c/djangoMINIO/__pycache__/wsgi.cpython-39.pyc -------------------------------------------------------------------------------- /djangoMINIO/asgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | ASGI config for djangoMINIO project. 3 | 4 | It exposes the ASGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/3.0/howto/deployment/asgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.asgi import get_asgi_application 13 | 14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'djangoMINIO.settings') 15 | 16 | application = get_asgi_application() 17 | -------------------------------------------------------------------------------- /djangoMINIO/settings.py: -------------------------------------------------------------------------------- 1 | """ 2 | Django settings for djangoMINIO project. 3 | 4 | Generated by 'django-admin startproject' using Django 3.0.7. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/3.0/topics/settings/ 8 | 9 | For the full list of settings and their values, see 10 | https://docs.djangoproject.com/en/3.0/ref/settings/ 11 | """ 12 | 13 | import os 14 | from datetime import timedelta 15 | from typing import List, Tuple 16 | 17 | # Build paths inside the project like this: os.path.join(BASE_DIR, ...) 18 | BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 19 | 20 | 21 | # Quick-start development settings - unsuitable for production 22 | # See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/ 23 | 24 | # SECURITY WARNING: keep the secret key used in production secret! 25 | SECRET_KEY = '2^#gsrh$e)gc8s5x8=#2tamef4fty@7wl7pi!$k3uc@vs61j%#' 26 | 27 | # SECURITY WARNING: don't run with debug turned on in production! 28 | DEBUG = True 29 | 30 | ALLOWED_HOSTS = ["*"] 31 | 32 | 33 | # Application definition 34 | 35 | INSTALLED_APPS = [ 36 | 'django.contrib.admin', 37 | 'django.contrib.auth', 38 | 'django.contrib.contenttypes', 39 | 'django.contrib.sessions', 40 | 'django.contrib.messages', 41 | 'django.contrib.staticfiles', 42 | 'rest_framework', 43 | 'core', 44 | 'django_minio_backend', 45 | ] 46 | 47 | MIDDLEWARE = [ 48 | 'django.middleware.security.SecurityMiddleware', 49 | 'django.contrib.sessions.middleware.SessionMiddleware', 50 | 'django.middleware.common.CommonMiddleware', 51 | 'django.middleware.csrf.CsrfViewMiddleware', 52 | 'django.contrib.auth.middleware.AuthenticationMiddleware', 53 | 'django.contrib.messages.middleware.MessageMiddleware', 54 | 'django.middleware.clickjacking.XFrameOptionsMiddleware', 55 | ] 56 | 57 | ROOT_URLCONF = 'djangoMINIO.urls' 58 | 59 | TEMPLATES = [ 60 | { 61 | 'BACKEND': 'django.template.backends.django.DjangoTemplates', 62 | 'DIRS': [], 63 | 'APP_DIRS': True, 64 | 'OPTIONS': { 65 | 'context_processors': [ 66 | 'django.template.context_processors.debug', 67 | 'django.template.context_processors.request', 68 | 'django.contrib.auth.context_processors.auth', 69 | 'django.contrib.messages.context_processors.messages', 70 | ], 71 | }, 72 | }, 73 | ] 74 | 75 | WSGI_APPLICATION = 'djangoMINIO.wsgi.application' 76 | 77 | 78 | # Database 79 | # https://docs.djangoproject.com/en/3.0/ref/settings/#databases 80 | 81 | DATABASES = { 82 | 'default': { 83 | 'ENGINE': 'django.db.backends.sqlite3', 84 | 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), 85 | } 86 | } 87 | 88 | 89 | # Password validation 90 | # https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators 91 | 92 | AUTH_PASSWORD_VALIDATORS = [ 93 | { 94 | 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', 95 | }, 96 | { 97 | 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', 98 | }, 99 | { 100 | 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', 101 | }, 102 | { 103 | 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', 104 | }, 105 | ] 106 | 107 | 108 | # Internationalization 109 | # https://docs.djangoproject.com/en/3.0/topics/i18n/ 110 | 111 | LANGUAGE_CODE = 'en-us' 112 | 113 | TIME_ZONE = 'UTC' 114 | 115 | USE_I18N = True 116 | 117 | USE_L10N = True 118 | 119 | USE_TZ = True 120 | 121 | 122 | # Static files (CSS, JavaScript, Images) 123 | # https://docs.djangoproject.com/en/3.0/howto/static-files/ 124 | 125 | 126 | STATIC_ROOT = os.path.join(BASE_DIR , 'static') 127 | STATIC_URL = '/static/' 128 | 129 | REST_FRAMEWORK = { 130 | 'DEFAULT_AUTHENTICATION_CLASSES': [ 131 | 'rest_framework_simplejwt.authentication.JWTAuthentication', 132 | ], 133 | } 134 | 135 | # ------------ MINIO ---------------- 136 | 137 | MINIO_EXTERNAL_ENDPOINT = "127.0.0.1:9000" 138 | MINIO_EXTERNAL_ENDPOINT_USE_HTTPS = False 139 | MINIO_ENDPOINT = 'minio:9000' 140 | MINIO_ACCESS_KEY = 'minio' 141 | MINIO_SECRET_KEY = 'minio123' 142 | MINIO_PRIVATE_BUCKETS = [ 143 | 'test', 144 | 145 | ] 146 | MINIO_PUBLIC_BUCKETS = [ 147 | "" 148 | ] 149 | MINIO_POLICY_HOOKS: List[Tuple[str, dict]] = [] 150 | 151 | MINIO_URL_EXPIRY_HOURS = timedelta(days=1) 152 | MINIO_MEDIA_FILES_BUCKET = 'test' -------------------------------------------------------------------------------- /djangoMINIO/urls.py: -------------------------------------------------------------------------------- 1 | from django.urls import path , include 2 | from rest_framework_simplejwt import views as jwt_views 3 | from django.contrib import admin 4 | 5 | urlpatterns = [ 6 | path('api/token/', jwt_views.TokenObtainPairView.as_view(), name='token_obtain_pair'), 7 | path('api/token/refresh/', jwt_views.TokenRefreshView.as_view(), name='token_refresh'), 8 | path("admin/" , admin.site.urls ), 9 | path('api/' , include("core.urls")) 10 | ] -------------------------------------------------------------------------------- /djangoMINIO/wsgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | WSGI config for djangoMINIO project. 3 | 4 | It exposes the WSGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/3.0/howto/deployment/wsgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.wsgi import get_wsgi_application 13 | 14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'djangoMINIO.settings') 15 | 16 | application = get_wsgi_application() 17 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | 3 | services: 4 | app: 5 | build: 6 | context: . 7 | ports: 8 | - "8000:8000" 9 | depends_on: 10 | - minio 11 | 12 | volumes: 13 | - .:/app 14 | networks: 15 | - django_network 16 | 17 | command: > 18 | sh -c "python3 manage.py migrate && 19 | python3 manage.py runserver 0.0.0.0:8000 && python manage.py initialize_buckets" 20 | 21 | minio: 22 | image: minio/minio:latest 23 | volumes: 24 | - s3-volume:/data 25 | ports: 26 | - "9000:9000" 27 | - "9001:9001" 28 | 29 | expose: 30 | - "9000" 31 | - "9001" 32 | 33 | networks: 34 | - django_network 35 | 36 | environment: 37 | MINIO_ROOT_USER: minio 38 | MINIO_ROOT_PASSWORD: minio123 39 | command: server /data --console-address :9001 40 | healthcheck: 41 | test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"] 42 | interval: 30s 43 | timeout: 20s 44 | retries: 3 45 | 46 | create_buckets: 47 | image: minio/mc:latest 48 | depends_on: 49 | - minio 50 | 51 | networks: 52 | - django_network 53 | 54 | entrypoint: > 55 | /bin/sh -c ' 56 | mc config host add s3 http://minio:9000 minio minio123 --api S3v4; 57 | [[ ! -z "`mc ls s3 | grep test`" ]] || mc mb s3/test; 58 | exit 0; 59 | ' 60 | 61 | volumes: 62 | s3-volume: 63 | 64 | networks: 65 | django_network: -------------------------------------------------------------------------------- /manage.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """Django's command-line utility for administrative tasks.""" 3 | import os 4 | import sys 5 | 6 | 7 | def main(): 8 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'djangoMINIO.settings') 9 | try: 10 | from django.core.management import execute_from_command_line 11 | except ImportError as exc: 12 | raise ImportError( 13 | "Couldn't import Django. Are you sure it's installed and " 14 | "available on your PYTHONPATH environment variable? Did you " 15 | "forget to activate a virtual environment?" 16 | ) from exc 17 | execute_from_command_line(sys.argv) 18 | 19 | 20 | if __name__ == '__main__': 21 | main() 22 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | asgiref==3.5.0 2 | certifi==2021.10.8 3 | configparser==5.2.0 4 | Django 5 | django-minio-backend==3.1.0b0 6 | djangorestframework==3.13.1 7 | python-dateutil==2.8.2 8 | pytz==2021.3 9 | six==1.16.0 10 | sqlparse==0.4.2 11 | urllib3==1.26.8 12 | djangorestframework_simplejwt 13 | -------------------------------------------------------------------------------- /test: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mazdakdev/Django-MINIO/ed4a420ed7d3e471caba07c29e235c48618e890c/test -------------------------------------------------------------------------------- /test.txt: -------------------------------------------------------------------------------- 1 | lorem ipsum dolar sit 2 | --------------------------------------------------------------------------------