Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/cinaaaa/djfiler

🗄️ Easy way to upload and host files in Django
https://github.com/cinaaaa/djfiler

django django-framework django-rest-framework django-uplaoding-module django-upload django-uploader host-files upload upload-easy upload-easy-django uploader uploadhandler

Last synced: about 1 month ago
JSON representation

🗄️ Easy way to upload and host files in Django

Awesome Lists containing this project

README

        



Django Filer


An Easy Way To Upload Files To Django



PyPI
PyPI - Django Version
PyPI - Python Version
PyPI - Wheel

## ✨ Features

- Upload Any File With Any Size In Any Format
- Saves Files Secure and Denied Foreign Requests
- Simple Import and Usage
- Host Files Safely With Simple Key

## 📦 Install

```bash
$ pip3 install djfiler
```

## 🔨 Usage

```python

# Import Django Filer & json
import json
from djfiler import djfiler

# Initial Django Filer
djs = djfiler.Filer('/dir/of/uploades', True)

''' djs can be any name you like '''
```

## 📤 Upload in Any Format
first create the function
urls.py
```python
def home(request):
if request.method == "POST":
callback = djs.upload(file=request.FILES['file name uploaded'], name="Optional" )
print(callback) # Its Returns {status:ok | fail,name: name of file ( Its Key Of File ),type: type of file }
```
Return Any File With A Simple Key (Key Is The String That We Return To You When Uploaded file)
then in html file create simple form that send files with a name
```html

Select File to upload:

```
then files saves to directory you inital in the Class

## 🎯 Host Files

urls.py
```python
path('images/', sendfile)

''' path name can be anything you like we just need the key parameters '''
```
views.py
```python
def sendfile(request, key):
callback = djs.find(key)
if callback != None:
data = json.loads(callback)
if data['find']:
with open(data['uri'], "rb") as f:
return HttpResponse(f.read(), content_type='*/*')
else:
return HttpResponse('ERROR TO SEND FILE')
else:
return HttpResponse('File Not Found')
```
file.html
```html

```
Thats All

## 🗜️ Test Code
Simply Test code like this
```shell
$ git clone https://github.com/E-RROR/djfiler
$ cd djfiler
$ python3 test-djfiler.py
```