gouthambs / Flask-FileUpload

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Build Status

Flask-FileUpload

A simple file upload flask extension.

  • Previews
  • Easy link copy
  • Delete and Upload with 3 clicks
  • Renaming of the file before uploading

Install

pip install Flask-FileUpload

Configuration

Required

SECRET_KEY="Any Secret key u want"

Optional

FILEUPLOAD_LOCALSTORAGE_IMG_FOLDER="folder"                         # Where to store the images if used the default LocalStorage
FILEUPLOAD_PREFIX="/any/prefix/u/want"                              # Blueprint prefix
FILEUPLOAD_ALLOWED_EXTENSIONS=["list", "of", "file", "extensions"]  # Allow only these extensions
FILEUPLOAD_ALLOW_ALL_EXTENSIONS=True                                # Allow all extensions
FILEUPLOAD_RANDOM_FILE_APPENDIX = True                              # Append a random 6 hash string to selected file
FILEUPLOAD_CONVERT_TO_SNAKE_CASE = True                             # Converts filenames to snake_case

jinja2 method and filter

fu_get_existing_files 
fu_filename 

They can be used everywhere in your jinja template for e.g: list all available files. Combined you can do something like:

<ul> 
  {% for file in fu_get_existing_files() %} 
    <li><a href="{{ file }}">{{ file|fu_filename }} </a></li> 
  {% endfor %} 
</ul> 

HowTo

from flask import Flask
from flask_fileupload import FlaskFileUpload

app = Flask(__name__)
app.config.from_object("config")
ffu = FlaskFileUpload(app)
lm = LoginManager(app)

class User(UserMixin):
    def __init__(self, user_id):
        self.id = user_id


@lm.user_loader
def load_user(user_id):
    return User(user_id)

Previews

About

License:MIT License


Languages

Language:Python 63.1%Language:HTML 31.9%Language:CSS 5.0%