Issue #6 new

Should be able to overwrite files (ie disable resolve_conflict)

cybertoast
created an issue

There are many instances when the uploaded file should overwrite the existing file, rather than creating a new file name. I would like to suggest an option to the uploads_set, to define whether to overwrite existing files or not, and have resolve_conflicts() check to see if this flag is set or not before creating new files. If overwrite is allowed, it would just return the existing filename.

Comments (1)

  1. Jeremy Epstein

    I got around this by manually checking if the uploaded file already exists on the filesystem, and deleting it if so. I.e. something like this:

    import os
    from werkzeug import secure_filename
    
    filename = secure_filename(form.myfile.data.filename)
    filepath = os.path.join(
        os.path.join(
            app.config['UPLOADS_FOLDER'],
            app.config['MYFILE_RELATIVE_PATH']),
        filename)
    
    if os.path.exists(filepath):
        os.remove(filepath)
    
    myfile_uploads.save(form.myfile.data, name=filename)
    

    This does the trick - but I agree, would be nicer if Flask-Uploads simply had an option to "resolve by overwriting" rather than to just "resolve by changing filename".

  2. Log in to comment