├── home ├── __init__.py ├── smtplib.py ├── tests.py ├── forms.py ├── admin.py ├── apps.py ├── urls.py ├── models.py ├── views.py └── serializers.py ├── fileupload ├── __init__.py ├── asgi.py ├── wsgi.py ├── urls.py └── settings.py ├── .gitignore ├── db.sqlite3 ├── manage.py ├── README.md └── templates ├── download.html └── upload.html /home/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /home/smtplib.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /fileupload/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | file_s 2 | __pycache__ 3 | migrations -------------------------------------------------------------------------------- /db.sqlite3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Anilnayak126/FileSharingApp/HEAD/db.sqlite3 -------------------------------------------------------------------------------- /home/tests.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | 3 | # Create your tests here. 4 | -------------------------------------------------------------------------------- /home/forms.py: -------------------------------------------------------------------------------- 1 | from django import forms 2 | 3 | class FileUploadForm(forms.Form): 4 | file = forms.FileField() 5 | receiver_email = forms.EmailField() 6 | -------------------------------------------------------------------------------- /home/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | from .models import * 3 | # Register your models here. 4 | 5 | admin.site.register(Folder) 6 | admin.site.register(Files) 7 | -------------------------------------------------------------------------------- /home/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class HomeConfig(AppConfig): 5 | default_auto_field = 'django.db.models.BigAutoField' 6 | name = 'home' 7 | -------------------------------------------------------------------------------- /fileupload/asgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | ASGI config for fileupload 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/5.1/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', 'fileupload.settings') 15 | 16 | application = get_asgi_application() 17 | -------------------------------------------------------------------------------- /fileupload/wsgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | WSGI config for fileupload 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/5.1/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', 'fileupload.settings') 15 | 16 | application = get_wsgi_application() 17 | -------------------------------------------------------------------------------- /home/urls.py: -------------------------------------------------------------------------------- 1 | from django.urls import path 2 | from django.conf.urls.static import static 3 | from django.conf import settings 4 | 5 | from .views import FileUploadView, FileDownloadView 6 | 7 | urlpatterns = [ 8 | path('', FileUploadView.as_view(), name='file-upload'), 9 | path('download//', FileDownloadView.as_view(), name='file-download'), 10 | ] 11 | 12 | if settings.DEBUG: 13 | urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) 14 | 15 | -------------------------------------------------------------------------------- /home/models.py: -------------------------------------------------------------------------------- 1 | # models.py 2 | 3 | from django.db import models 4 | import uuid 5 | import os 6 | 7 | def get_upload_path(instance, filename): 8 | return os.path.join(str(instance.folder.uid), filename) 9 | 10 | class Folder(models.Model): 11 | uid = models.UUIDField(primary_key=True, editable=False, default=uuid.uuid4) 12 | created_at = models.DateField(auto_now_add=True) 13 | 14 | class Files(models.Model): 15 | folder = models.ForeignKey(Folder, on_delete=models.CASCADE) 16 | file = models.FileField(upload_to=get_upload_path) 17 | created_at = models.DateField(auto_now=True) 18 | -------------------------------------------------------------------------------- /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 | """Run administrative tasks.""" 9 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'fileupload.settings') 10 | try: 11 | from django.core.management import execute_from_command_line 12 | except ImportError as exc: 13 | raise ImportError( 14 | "Couldn't import Django. Are you sure it's installed and " 15 | "available on your PYTHONPATH environment variable? Did you " 16 | "forget to activate a virtual environment?" 17 | ) from exc 18 | execute_from_command_line(sys.argv) 19 | 20 | 21 | if __name__ == '__main__': 22 | main() 23 | -------------------------------------------------------------------------------- /fileupload/urls.py: -------------------------------------------------------------------------------- 1 | """ 2 | URL configuration for fileupload project. 3 | 4 | The `urlpatterns` list routes URLs to views. For more information please see: 5 | https://docs.djangoproject.com/en/5.1/topics/http/urls/ 6 | Examples: 7 | Function views 8 | 1. Add an import: from my_app import views 9 | 2. Add a URL to urlpatterns: path('', views.home, name='home') 10 | Class-based views 11 | 1. Add an import: from other_app.views import Home 12 | 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') 13 | Including another URLconf 14 | 1. Import the include() function: from django.urls import include, path 15 | 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) 16 | """ 17 | from django.contrib import admin 18 | from django.urls import path,include 19 | 20 | from django.conf.urls.static import static 21 | from django.conf import settings 22 | from django.contrib.staticfiles.urls import staticfiles_urlpatterns 23 | 24 | 25 | urlpatterns = [ 26 | 27 | path('',include('home.urls')), 28 | path('admin/', admin.site.urls), 29 | ] 30 | 31 | 32 | -------------------------------------------------------------------------------- /home/views.py: -------------------------------------------------------------------------------- 1 | # views.py 2 | 3 | from django.shortcuts import render, get_object_or_404 4 | from rest_framework.views import APIView 5 | from rest_framework.response import Response 6 | from rest_framework import status 7 | from .models import Folder 8 | from .serializers import FileListSerializer 9 | import os 10 | from django.http import HttpResponse, FileResponse 11 | from django.conf import settings 12 | 13 | class FileUploadView(APIView): 14 | def get(self, request): 15 | return render(request, 'upload.html') 16 | 17 | def post(self, request): 18 | print(request.data) # For debugging 19 | 20 | serializer = FileListSerializer(data=request.data) 21 | 22 | if serializer.is_valid(): 23 | folder_data = serializer.save() 24 | download_link = request.build_absolute_uri(f"/download/{folder_data['folder']}/") 25 | return render(request, 'upload.html', {'download_link': download_link}) 26 | 27 | return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) 28 | 29 | class FileDownloadView(APIView): 30 | def get(self, request, folder_uid): 31 | folder = get_object_or_404(Folder, uid=folder_uid) 32 | zip_path = f'public/static/zip/{folder.uid}.zip' 33 | 34 | # Check if the zip file exists 35 | if os.path.exists(zip_path): 36 | # Serve the download page 37 | return render(request, 'download.html', {'zip_path': f'{settings.STATIC_URL}zip/{folder.uid}.zip'}) 38 | 39 | return Response({'error': 'File not found'}, status=status.HTTP_404_NOT_FOUND) -------------------------------------------------------------------------------- /home/serializers.py: -------------------------------------------------------------------------------- 1 | import os 2 | import shutil 3 | from rest_framework import serializers 4 | from .models import Folder, Files # Adjust the import according to your project structure 5 | 6 | class FileListSerializer(serializers.Serializer): 7 | files = serializers.ListField( 8 | child=serializers.FileField(max_length=100000, allow_empty_file=False, use_url=False) 9 | ) 10 | folder = serializers.CharField(required=False) 11 | 12 | def zip_files(self, folder): 13 | os.makedirs('public/static', exist_ok=True) 14 | os.makedirs('public/static/zip', exist_ok=True) 15 | 16 | folder_path = os.path.join('public/static', str(folder.uid)) 17 | zip_path = os.path.join('public/static/zip', str(folder.uid)) 18 | 19 | if os.path.exists(folder_path) and os.listdir(folder_path): 20 | shutil.make_archive(zip_path, 'zip', folder_path) 21 | else: 22 | print('No files to zip in the specified folder.') 23 | 24 | def create(self, validated_data): 25 | folder = Folder.objects.create() 26 | files = validated_data.pop('files') 27 | folder_path = os.path.join('public/static', str(folder.uid)) 28 | os.makedirs(folder_path, exist_ok=True) 29 | 30 | for file in files: 31 | Files.objects.create(folder=folder, file=file) 32 | 33 | # Save file to destination path for zipping later 34 | destination_path = os.path.join(folder_path, file.name) 35 | with open(destination_path, 'wb+') as destination: 36 | for chunk in file.chunks(): 37 | destination.write(chunk) 38 | 39 | self.zip_files(folder) 40 | return {'folder': str(folder.uid)} 41 | -------------------------------------------------------------------------------- /fileupload/settings.py: -------------------------------------------------------------------------------- 1 | import os 2 | from pathlib import Path 3 | 4 | # Build paths inside the project like this: BASE_DIR / 'subdir'. 5 | BASE_DIR = Path(__file__).resolve().parent.parent 6 | 7 | # SECURITY WARNING: keep the secret key used in production secret! 8 | SECRET_KEY = 'your-secret-key' # Replace with your secret key 9 | 10 | # SECURITY WARNING: don't run with debug turned on in production! 11 | DEBUG = True 12 | 13 | ALLOWED_HOSTS = ['*'] # Allow all hosts for development 14 | 15 | # Application definition 16 | INSTALLED_APPS = [ 17 | 'django.contrib.admin', 18 | 'django.contrib.auth', 19 | 'django.contrib.contenttypes', 20 | 'django.contrib.sessions', 21 | 'django.contrib.messages', 22 | 'django.contrib.staticfiles', 23 | 'rest_framework', 24 | 'home' 25 | ] 26 | 27 | MIDDLEWARE = [ 28 | 'django.middleware.security.SecurityMiddleware', 29 | 'django.contrib.sessions.middleware.SessionMiddleware', 30 | 'django.middleware.common.CommonMiddleware', 31 | 'django.middleware.csrf.CsrfViewMiddleware', 32 | 'django.contrib.auth.middleware.AuthenticationMiddleware', 33 | 'django.contrib.messages.middleware.MessageMiddleware', 34 | 'django.middleware.clickjacking.XFrameOptionsMiddleware', 35 | ] 36 | 37 | ROOT_URLCONF = 'fileupload.urls' 38 | 39 | TEMPLATES = [ 40 | { 41 | 'BACKEND': 'django.template.backends.django.DjangoTemplates', 42 | 'DIRS': [os.path.join('templates')], 43 | 'APP_DIRS': True, 44 | 'OPTIONS': { 45 | 'context_processors': [ 46 | 'django.template.context_processors.debug', 47 | 'django.template.context_processors.request', 48 | 'django.contrib.auth.context_processors.auth', 49 | 'django.contrib.messages.context_processors.messages', 50 | ], 51 | }, 52 | }, 53 | ] 54 | 55 | WSGI_APPLICATION = 'fileupload.wsgi.application' 56 | 57 | # Database settings 58 | DATABASES = { 59 | 'default': { 60 | 'ENGINE': 'django.db.backends.sqlite3', 61 | 'NAME': BASE_DIR / 'db.sqlite3', 62 | } 63 | } 64 | 65 | # Password validation 66 | AUTH_PASSWORD_VALIDATORS = [ 67 | { 68 | 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', 69 | }, 70 | { 71 | 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', 72 | }, 73 | { 74 | 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', 75 | }, 76 | { 77 | 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', 78 | }, 79 | ] 80 | 81 | # Internationalization 82 | LANGUAGE_CODE = 'en-us' 83 | TIME_ZONE = 'UTC' 84 | USE_I18N = True 85 | USE_TZ = True 86 | 87 | 88 | STATIC_URL = '/static/' 89 | 90 | 91 | 92 | DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' 93 | 94 | ''' 95 | import os 96 | 97 | STATIC_ROOT = 'staticfiles' 98 | STATIC_URL = '/static/' 99 | STATIC_ROOT = os.path.join(BASE_DIR,'staticfiles') 100 | 101 | STATICFILES_DIR = { 102 | os.path.join(BASE_DIR , "public/static") 103 | } 104 | 105 | MEDIA_ROOT = os.path.join(BASE_DIR, 'public/static') 106 | MEDIA_URL = '/media/' 107 | ''' 108 | 109 | BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 110 | STATIC_URL = '/static/' 111 | STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles') 112 | 113 | STATICFILES_DIRS = [ 114 | os.path.join(BASE_DIR, "public/static"), # Extra static files directory 115 | ] 116 | 117 | 118 | MEDIA_URL = '/media/' 119 | MEDIA_ROOT = os.path.join(BASE_DIR, 'media') 120 | 121 | ''' 122 | EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' 123 | EMAIL_HOST = 'smtp.mail.yahoo.com' # Yahoo SMTP server 124 | EMAIL_PORT = 587 # Use 587 for TLS 125 | EMAIL_USE_TLS = True # Use TLS 126 | EMAIL_HOST_USER = 'nayak._official@yahoo.com' # Your Yahoo email address 127 | EMAIL_HOST_PASSWORD = '' 128 | ''' -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 📁 File Sharing App 2 | 3 | A robust file-sharing application built using **Django** and **Django REST Framework** (DRF), combined with **HTML** and **CSS** for the front-end. This project includes advanced REST API capabilities, along with secure file management, upload, and download functionalities. The app also incorporates the `shutil` module for creating ZIP files, enabling users to bundle multiple files for easy sharing and download. 4 | 5 | --- 6 | 7 | ## 📌 Features 8 | 9 | - **File Upload & Management**: Users can upload files, view file details, and manage their uploads. 10 | - **File Compression**: Multi-file compression into ZIP format using the `shutil` module for efficient storage and download. 11 | - **Secure File Sharing**: Secure access to file downloads with REST API endpoints. 12 | - **RESTful API**: Advanced API endpoints with authentication and authorization for file upload, retrieval, and download. 13 | - **Responsive Design**: A clean, responsive design created with HTML and CSS. 14 | 15 | --- 16 | 17 | ## 🛠️ Tech Stack 18 | 19 | - **Backend**: Django, Django REST Framework, `shutil` for ZIP functionality 20 | - **Frontend**: HTML, CSS 21 | - **Database**: SQLite3 22 | 23 | --- 24 | 25 | ## 🚀 Getting Started 26 | 27 | ### Prerequisites 28 | 29 | - Python 3.x 30 | - Django 31 | - Django REST Framework 32 | 33 | ### Installation 34 | 35 | 1. **Clone the Repository** 36 | 37 | ```bash 38 | https://github.com/Anilnayak126/FileSharingApp.git 39 | cd FileSharingApp 40 | 41 | 42 | 43 | 2. **Backend Setup** 44 | - Create a virtual environment (optional but recommended): 45 | ```bash 46 | python -m venv venv 47 | source venv/bin/activate # On Windows use `venv\Scripts\activate` 48 | - Install the necessary dependencies 49 | ```bash 50 | pip install -r requirements.txt 51 | - Set up the database and run migrations: 52 | ```bash 53 | python manage.py migrate 54 | ``` 55 | - Create a superuser to access the admin panel (optional): 56 | ```bash 57 | python manage.py createsuperuser 58 | ``` 59 | - Start the Django development server: 60 | ```bash 61 | python manage.py runserver 62 | ``` 63 | 64 | 3. **📂 Project Structure** 65 | ```bash 66 | file-sharing-app/ 67 | │ 68 | ├── file_sharing/ # Main Django project directory 69 | │ ├── settings.py # Django settings 70 | │ ├── urls.py # Project URL configurations 71 | │ ├── views.py # API and file management views 72 | │ ├── serializers.py # DRF serializers 73 | │ ├── models.py # Database models for file storage 74 | │ └── admin.py # Admin configurations 75 | │ 76 | ├── static/ # HTML and CSS files 77 | │ ├── css/ # CSS styling for the front-end 78 | │ └── templates/ # HTML templates 79 | │ 80 | ├── requirements.txt # List of project dependencies 81 | └── README.md # Project documentation 82 | ``` 83 | 4. **🔥 Key Highlights** 84 | 85 | - **Advanced API Development**: File management endpoints are structured with RESTful principles, featuring secure file access and comprehensive response handling. 86 | - **File Compression**: Efficient use of Python's shutil to compress multiple files into a single ZIP file, enhancing download efficiency and usability. 87 | - **Secure Access**: Token-based authentication for controlled access to file resources and actions. 88 | - **Simple UI**: HTML/CSS-based front-end for straightforward file upload and management. 89 | 90 | 5. **📝 Future Improvements** 91 | - **Frontend Framework Integration**: Consider integrating a JavaScript framework (like React or Vue.js) for a more dynamic user interface. 92 | - **Cloud Storage Integration**: Implement cloud storage solutions (like AWS S3 or Google Cloud Storage) for enhanced scalability and file management. 93 | - **User Notifications**: Add email or push notifications to inform users about file uploads or downloads. 94 | **File Versioning**: Introduce file versioning to keep track of changes made to files over time. 95 | 96 | 97 | 98 | ### Instructions 99 | 1. Replace `https://github.com/Anilnayak126/FileSharingApp.git` with the actual URL of your GitHub repository. 100 | 2. Update the email address in the contact section to your actual email. 101 | 3. Save this content as `README.md` in your project directory. 102 | 103 | This enhanced `README.md` provides a detailed overview of your project, guiding users on setup, features, and potential future improvements! 104 | 105 | 106 | 107 | -------------------------------------------------------------------------------- /templates/download.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Download Files 7 | 159 | 160 | 161 | 170 | 171 |
172 |

Download Your Files

173 | Click here to download your files 174 |
Download started successfully!
175 |
176 |
Anil's FileHub - Anil's FileHub - Anil's FileHub - Anil's FileHub
177 | 178 | 181 | 182 | 188 | 189 | 190 | -------------------------------------------------------------------------------- /templates/upload.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Anil's FileHub 7 | 8 | 9 | 194 | 195 | 196 |
Anil's FileHub - Anil's FileHub - Anil's FileHub - Anil's FileHub
197 | 198 | 208 | 209 |
210 |

Upload Your Files

211 |
212 | {% csrf_token %} 213 | 214 | 215 |
216 | 217 | {% if download_link %} 218 | 223 | {% endif %} 224 |
225 | 226 | 229 | 230 | 231 | 240 | 241 | 242 | --------------------------------------------------------------------------------