• Phil Schleihauf's avatar
    Update filename on werkzeug FileStorage for uploaded files · 96f5375c
    Phil Schleihauf authored
    This is an issue for fields whose name might be changed at any point, like any image ending in "jpeg" (which will be renamed to "jpg". That would cause the actual file to be saved to disk with ".jpeg", but be saved elsewhere as ".jpg".
    
    This example (mostly copied from the example in `examples/forms/simple.py`) shows it better than I can explain:
    
        import os
        from flask import Flask
        from flask.ext.admin import Admin, form
        from flask.ext.admin.contrib import sqla
        from flask.ext.sqlalchemy import SQLAlchemy
    
        app = Flask(__name__)
        app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///hello.db'
        db = SQLAlchemy(app)
    
        os.path.isdir('static') or os.mkdir('static')
    
        class Photo(db.Model):
            id = db.Column(db.Integer, primary_key=True)
            path = db.Column(db.Unicode(128))
    
        class PhotoView(sqla.ModelView):
            form_extra_fields = {'path': form.ImageUploadField('Photo', base_path='static')}
    
        admin = Admin(app, 'Photos are broken!')
        admin.add_view(PhotoView(Photo, db.session))
    
        db.create_all()
        app.run(debug=True)
    
    ... try uploading files with `.jpeg` vs `.jpg` extensions. It's pretty broken.
    96f5375c
Name
Last commit
Last update
babel Loading commit data...
doc Loading commit data...
examples Loading commit data...
flask_admin Loading commit data...
.gitignore Loading commit data...
.gitmodules Loading commit data...
.travis.yml Loading commit data...
AUTHORS Loading commit data...
LICENSE Loading commit data...
MANIFEST.in Loading commit data...
Makefile Loading commit data...
NOTICE Loading commit data...
README.rst Loading commit data...
TODO.txt Loading commit data...
projects.rst Loading commit data...
setup.cfg Loading commit data...
setup.py Loading commit data...
travis.txt Loading commit data...