Skip to main content

replace for flask-uploads

Project description

jd-flask-uploads

作为 flask-uploads 的替代品,因为 flask-uploads 在 Pypi上没有更新版本,从github上源码安装不太方便。

安装

pip install jd-flask-uploads

用法

from jd_flask_uploads import UploadSet, IMAGES

# Upload Sets
# An “upload set” is a single collection of files. You just declare them in the code:
photos = UploadSet('photos', IMAGES)


# And then you can use the save method to save uploaded files and path and url to access them. For example:

@app.route('/upload', methods=['GET', 'POST'])
def upload():
    if request.method == 'POST' and 'photo' in request.files:
        filename = photos.save(request.files['photo'])
        rec = Photo(filename=filename, user=g.user.id)
        rec.store()
        flash("Photo saved.")
        return redirect(url_for('show', id=rec.id))
    return render_template('upload.html')

@app.route('/photo/<id>')
def show(id):
    photo = Photo.load(id)
    if photo is None:
        abort(404)
    url = photos.url(photo.filename)
    return render_template('show.html', url=url, photo=photo)

模块内方法说明

函数、对象名称 类型 说明
UploadSet 对象 文件上传主对象
configure_uploads 函数 配置本上传对象,在 Flask App 创建之后
patch_request_class 函数 配置 Flask App 内置测试服务的文件上传大小限制
extension 函数 返回文件扩展名
lowercase_ext 函数 返回文件扩展名(小写格式)
addslash 函数 url、路径后添加反斜杠 '/',若存在则不添加

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

jd-flask-uploads-0.3.1.tar.gz (10.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

jd_flask_uploads-0.3.1-py3-none-any.whl (10.2 kB view details)

Uploaded Python 3

File details

Details for the file jd-flask-uploads-0.3.1.tar.gz.

File metadata

  • Download URL: jd-flask-uploads-0.3.1.tar.gz
  • Upload date:
  • Size: 10.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.6

File hashes

Hashes for jd-flask-uploads-0.3.1.tar.gz
Algorithm Hash digest
SHA256 d75f6fe412586ed34dec3a7d0a22248eee92607e2cef0199d098824a37e5b762
MD5 8bb9f71b77d89e719531391336ac8063
BLAKE2b-256 18330fe06c3734ef6475953dcd7f92d0bc8d2569a6322d2cba5f26da9572891c

See more details on using hashes here.

File details

Details for the file jd_flask_uploads-0.3.1-py3-none-any.whl.

File metadata

File hashes

Hashes for jd_flask_uploads-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8659e6e413c1822f1751e96c9376c087c73660334ede08bcd9eaaa5b735e6f02
MD5 f0164049ed2d6ddc2183e950138e2f47
BLAKE2b-256 2205ab41a8e3057667e0c0f53b8b83575d677b0002b0efe17b075396e08d93bb

See more details on using hashes here.

Supported by

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