Skip to main content

Flexible and efficient upload handling for Flask

Project description

CI Status https://coveralls.io/repos/github/jugmac00/flask-reuploaded/badge.svg?branch=master PyPI PyPI - Python Version Requirements Status https://img.shields.io/pypi/l/hibpcli

Flask-Reuploaded

Flask-Reuploaded provides file uploads for Flask.

Notes on this package

This is an independently maintained version of Flask-Uploads based on the 0.2.1 version of the original, but also including four years of unreleased changes - at least not released to PyPi.

Noteworthy is the fix for the Werkzeug API change.

Goals

  • Flask-Reuploaded is a stable drop-in replacement for Flask-Uploads

  • regain momentum for this widely used package

  • provide working PyPi packages

Migration guide from Flask-Uploads

If you have used Flask-Uploads and want to migrate to Flask-Reuploaded, you only have to install Flask-Reuploaded instead of Flask-Uploads.

That’s all!

So, if you use pip to install your packages, instead of …

$ pip install `Flask-Uploads`  # don't do this! package is broken

… just do …

$ pip install `Flask-Reuploaded`

Flask-Reuploaded is a drop-in replacement.

This means you do not have to change a single line of code.

Installation

$ pip install Flask-Reuploaded

Getting started

create an UploadSet

from flask_uploads import IMAGES

photos = UploadSet("photos", IMAGES)

configure your Flask app and this extension

app.config["UPLOADED_PHOTOS_DEST"] = "static/img"
app.config["SECRET_KEY"] = os.urandom(24)
configure_uploads(app, photos)

use photos in your view function

photos.save(request.files['photo'])

See below for a complete example.

Documentation

The documentation can be found at…

https://flask-reuploaded.readthedocs.io/en/latest/

Minimal example application

Application code

import os

from flask import Flask, flash, render_template, request
# please note the import from `flask_uploads` - not `flask_reuploaded`!!
# this is done on purpose to stay compatible with `Flask-Uploads`
from flask_uploads import IMAGES, UploadSet, configure_uploads

app = Flask(__name__)
photos = UploadSet("photos", IMAGES)
app.config["UPLOADED_PHOTOS_DEST"] = "static/img"
app.config["SECRET_KEY"] = os.urandom(24)
configure_uploads(app, photos)


@app.route("/", methods=['GET', 'POST'])
def upload():
    if request.method == 'POST' and 'photo' in request.files:
        photos.save(request.files['photo'])
        flash("Photo saved successfully.")
        return render_template('upload.html')
    return render_template('upload.html')

HTML code for upload.html

<!doctype html>
<html lang=en>
<head>
    <meta charset=utf-8>
    <title>Flask-Reuploaded Example</title>
</head>
<body>
    {% with messages = get_flashed_messages() %}
    {% if messages %}
    <ul class=flashes>
    {% for message in messages %}
        <li>{{ message }}</li>
    {% endfor %}
    </ul>
    {% endif %}
{% endwith %}

<form method=POST enctype=multipart/form-data action="{{ url_for('upload') }}">
    <input type=file name=photo>
    <button type="submit">Submit</button>
</form>
</body>
</html>

Contributing

Contributions are more than welcome.

Please have a look at the open issues.

There is also a short contributing guide.

Changelog

0.4.0

  • add type annotations

  • drop support for Python 2 and Python 3.5 (#8)

  • deprecate patch_request_class (#43)

  • use a src directory for source code (#21)

  • add tox env for check-python-versions (#20)

  • add flake8-bugbear

  • add short contribution guide (#6)

  • add getting started (#59)

  • delete broken example and add minimal example to README (#15)

  • add support for Python 3.9

  • use gh actions instead of Travis CI

0.3.2

  • documentation update (#5)

    • update docs/index.rst

    • use blue ReadTheDocs theme

    • update sphinx configuration

    • add documentation link to setup.py, so it shows on PyPi

    • add note about documentation in the README file

    • delete old theme files

  • configure isort to force single line imports

0.3.1

  • add badges to README (# 31)

  • add migration guide from Flask-Uploads to Flask-Reuploaded (#11)

  • add packaging guide (#28)

  • update installation instruction in README

0.3

Besides including four years of unreleased changes from the original package, most notable the fix for the Werkzeug API change, the following changes happened since forking the original package.

  • rename package from Flask-Uploads to Flask-Reuploaded (#10)

  • update setup.py (#12)

  • start using pre-commit.com (#4)

  • update README (#14)

  • setup CI (Travis) (#3)

  • fix broken tests (#13)

  • make use of pytest instead of the no longer maintained nose (#2)

  • add a changelog and start tracking changes (#1)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

Flask-Reuploaded-0.4.0.tar.gz (25.8 kB view details)

Uploaded Source

Built Distribution

Flask_Reuploaded-0.4.0-py3-none-any.whl (14.5 kB view details)

Uploaded Python 3

File details

Details for the file Flask-Reuploaded-0.4.0.tar.gz.

File metadata

  • Download URL: Flask-Reuploaded-0.4.0.tar.gz
  • Upload date:
  • Size: 25.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.55.1 CPython/3.8.7

File hashes

Hashes for Flask-Reuploaded-0.4.0.tar.gz
Algorithm Hash digest
SHA256 5a74c1278b8dba9a0dd95b410944695d84e801fd4acf63f7a9d90c3c81a77ea6
MD5 ec0695433b3febaa094574d6e81d4707
BLAKE2b-256 5943a5a48847d813ee7de32f7b6fd4ced09f6b4c15001c86294af0fac08cf64b

See more details on using hashes here.

File details

Details for the file Flask_Reuploaded-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: Flask_Reuploaded-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 14.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.55.1 CPython/3.8.7

File hashes

Hashes for Flask_Reuploaded-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c2a69dc58fdedd85dea242bb816cfc73d52978a5fe81ee2191acfc8cb1716f6b
MD5 414af93ac1d73cd9070ccc28fd71d901
BLAKE2b-256 ea7ed832dca256f4f6afff735a18b33db450d80c78d75fe5698aed7301ff3769

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page