jugmac00 / flask-reuploaded

File uploads for Flask.
https://github.com/jugmac00/flask-reuploaded
MIT License
63 stars 12 forks source link

understanding file renaming within flask_uploads. (any filename changes other than " " replaced by "_" ? ) #131

Closed aspiringguru closed 2 years ago

aspiringguru commented 2 years ago

I'm using

from flask_uploads import configure_uploads, ALL, UploadSet
all = UploadSet('all', ALL)
configure_uploads(app, all)

then in a flask route

form = MyForm()
    if form.validate_on_submit():
        filename = form.all.data.filename
        fname = all.save(form.all.data)

filename and fname will not be the same. fname appears to replace any spaces in filename with "_". if duplicate filenames are uploaded, fname appears to append "_01", "_02" etc to the filename uploaded.

just wanted to check I'm interpreting the observed behaviour correctly as I couldn't find the relevant source code.

caveat : while I've checked the installed packages within the virtual env I'm using, I was a bit thrown by pip freeze not showing 'flask_uploads' as an installed package. It's remotely possible my 'import flask_uploads' is pulling flask_uploads from somewhere else (?)

pip freeze 
.....
Flask==2.1.2
Flask-Reuploaded==1.2.0
Flask-WTF==1.0.1

otherwise. thanks for publishing the package. idk why more ppl aren't using it.

jugmac00 commented 2 years ago

a) renaming

The relevant source code you were looking for is found here: https://github.com/jugmac00/flask-reuploaded/blob/31055e625e1be0a1b7bcaadc1d0c81381a26afe1/src/flask_uploads/flask_uploads.py#L346-L365

b) Flask-Reuploaded vs flask_uploads

while I've checked the installed packages within the virtual env I'm using, I was a bit thrown by pip freeze not showing 'flask_uploads' as an installed package.

This is explained in the README at the front page of this repository. https://github.com/jugmac00/flask-reuploaded

In short - this package here is a drop-in replacement for the unmaintained flask-uploads - drop-in in a sense, that you even do not have to change the import statement.

The "trick" here is... the package name is Flask-Reuploaded, but the folders are named src/flask_uploads.

c) usage

idk why more ppl aren't using it.

monthly downloads

| Flask-Reuploaded | 5,568 | | flask-uploads | 15,050 |

source https://pepy.tech/

I am ok with the numbers. I am still a bit surprised that so many people download a completely outdated library - which even contains some security issues, but there is nothing I can do about it.

A general thought on the "low" download numbers... flask-uploads was really needed many years ago, as Flask did not provide an easy way to handle file upload. Meanwhile it does - so many developers just use plain Flask. This is absolutely ok. I created Flask-Reuploaded especially to help those developers, who struggle to work with plain Flask, and who maybe followed one of the many, many flask-uploads tutorials out there, but then were frustrated as the package was broken.

P.S.: There is no need to cross-post here and on StackOverflow.