Skip to content

cinaaaa/djfiler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

44 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

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

$ pip3 install djfiler

πŸ”¨ Usage

# 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

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

<form action="/path/to/any/url" method="post" enctype="multipart/form-data">
    Select File to upload:
    <input type="file" name="fileToUpload" id="fileToUpload">
    <input type="submit" value="Upload Image" name="submit">
</form>

then files saves to directory you inital in the Class

🎯 Host Files

urls.py

 path('images/<slug:key>', sendfile)
 
 ''' path name can be anything you like we just need the key parameters '''

views.py

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

<img src="/images/<key>" />

Thats All

πŸ—œοΈ Test Code

Simply Test code like this

$ git clone https://github.com/E-RROR/djfiler
$ cd djfiler
$ python3 test-djfiler.py