Code Monkey home page Code Monkey logo

djfiler's Introduction

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

djfiler's People

Contributors

cinaaaa avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

json-mamoa

djfiler's Issues

Improvement

Need Help for any code refactor or Improvement Pulls : )

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.