Code Monkey home page Code Monkey logo

flask-uploads's Introduction

Flask-Uploads

Flask-Uploads provides file uploads for Flask.

Installation

pip install flask-uploads

flask-uploads's People

Contributors

fdemmer avatar greyli avatar hangim avatar imposeren avatar jugmac00 avatar leafstorm avatar maxcountryman avatar noracodes avatar pmlandwehr avatar rduplain avatar shrimpdede avatar trirpi avatar wjt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

flask-uploads's Issues

pip package of flask-uploads is not update

in this Repository of flask-uploads, in 26 line the from werkzeug import secure_filename, FileStorage
is updated to
from werkzeug.datastructures import FileStorage
from werkzeug.utils import secure_filename

but when you download the flask-uploads from pip you don't get this update

when you create a docker container and the app is included this package your app in docker goes wrong and that container doesn't create

please help me

Unique filename feature?

Let's say i have

# alldocs = UploadSet('alldocs', DOCUMENTS)
alldocs.save(request.files[form.file_input.data.name])

as adapted from here under Updating The Route.

Now i want each filename to be unique. If i try to add some random chars at the beginning:

alldocs.save(rand_func() + '_' + request.files[form.file_input.data.name])
# to get like werugt387tgr36_file.pdf

it says:

TypeError: storage must be a werkzeug.FileStorage

Maybe there should be an easy way to have unique filename?

current release is broken, new release?

Past werkzeug v0.16.1 we get the following error:

 File "/Projects/flaskinni/venv/lib/python3.7/site-packages/flask_uploads.py", line 26, in <module>
from werkzeug import secure_filename, FileStorage
ImportError: cannot import name 'secure_filename' from 'werkzeug''

It appears the fix has already been made. Can it be deployed to pypi?

Include tests in PyPI tarballs

Hi, could you include tests in PyPI tarballs? It would make packaging easier for us at Gentoo. Otherwise, we need to pull them from GitHub.

random fileName

import hashlib

.....
in function save,you need add some code:
oldName, ext = storage.filename.split(',')
hl = hashlib.md5()
hl.update(oldName.encode())
newName = hl.hexdigest()+'.'+ext

basename = self.get_basename(newName) #storage.filename
.....

When 0.2.2?

The latest version on pypi is still 0.2.1 which doesn't get the import from werkzeug right. This does not seem to be an issue in the master branch. It would be convenient if this were released as a new version.

Push 0.2.1 tag to GitHub

Please push the tag for 0.2.1 to GitHub. Since the tarball on PyPI does not contain the tests we rely on the GitHub tarball for creating the package for Gentoo Linux.

A question for UploadSet.save()

When I use UploadSet instance save to file, It's raise UploadNotAllowed Exception. I find it strange,so, I read your code. finally, I found it, Because I'm Chinese, the filename maybe is Chinese. But, when the filename is Chinese, use the werkzeug.secure_filename(), the result is the extension. For example.
filename = 'boy.jpg'
res = secure_filename(filename)
res is boy.jpg, but when the filename is chinese
filename = '男孩.jpg'
res = secure_filename(filename)
res is jpg.

cant not add .docx extension auto

when upload the docx file,the file extensions cannot be added automatically
such as:
save_path='09\01'
save_name='124'
restfile.save(request.files['file'], folder=save_path, name=save_name)

after execution, the disk file is not extended,but when using .jpg or .png file,the function is ok.

Automated tag-based releases

To preface this conversation, I'll remind everyone that GitHub issues, my Twitter account, and my personal email are not forums for requesting PyPI releases: as I've previously mentioned, because Python tooling generally makes it trivial to install from git directly, there's nothing stopping you from using a given revision and so the urgency of a PyPI release seems diminished. Again, I'm not offering this as a topic of discussion and I'll consider any issues, comments, DMs, or emails about this as off-topic and I will delete or remove them. Please be respectful and understand for this repo your concern is heard and there's no further need to continue asking.

With that out of the way, I want to offer an automated path for PyPI releases. If someone is so motivated, I would accept a PR that implements tag-based releases via GitHub actions. This shouldn't be too difficult, but does require moving the repo to Actions. If someone wants to do this leg work, I'll ensure the necessary secrets are available. This will allow the maintainers (including myself) to easily create releases without having to setup the local tooling to do so (truly a pain and not something I personally have the time for at the moment).

Package and tests are broken since release of Werkzeug 1.0.0

Werkzeug has moved some long deprecated functions/Classes to separate modules.

Since the release of Werkzeug 1.0.0 this package here is broken, also the tests do not work any more.

I created #28 to fix the broken imports.

Could you please cut a new release after merging the PR?

Thanks a lot!

P.S.: If you activate Travis for this repository, I'd volunteer to create a config file and do some minor housekeeping.

Will this be resolved?

Traceback (most recent call last):
File "e:\vessel_app\vessel_env\lib\site-packages\flask\cli.py", line 256, in locate_app
import(module_name)
File "E:\vessel_app\Vessel-app\Back-end\wsgi.py", line 1, in
from vessel_app import create_app
File "E:\vessel_app\Vessel-app\Back-end\vessel_app_init_.py", line 12, in
from flask_uploads import UploadSet, configure_uploads, IMAGES, patch_request_class
File "e:\vessel_app\vessel_env\lib\site-packages\flask_uploads.py", line 26, in
from werkzeug import secure_filename, FileStorage
ImportError: cannot import name 'secure_filename' from 'werkzeug' (e:\vessel_app\vessel_env\lib\site-packages\werkzeug_init_.py)

https://stackoverflow.com/questions/61628503/flask-uploads-importerror-cannot-import-name-secure-filename

Pypi package seems broken on Python 3.9

`
$ pip install flask-upload

Collecting flask-upload
Downloading Flask-Upload-0.0.1.zip (3.4 kB)
ERROR: Command errored out with exit status 1:
command: .../venv/bin/python3 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-hq1ysap4/flask-upload_811c59d1191c4976a8cb3ac2017a1131/setup.py'"'"'; file='"'"'/tmp/pip-install-hq1ysap4/flask-upload_811c59d1191c4976a8cb3ac2017a1131/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(file);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, file, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-k6iw5_li
cwd: /tmp/pip-install-hq1ysap4/flask-upload_811c59d1191c4976a8cb3ac2017a1131/
Complete output (9 lines):
Traceback (most recent call last):
File "", line 1, in
File "/tmp/pip-install-hq1ysap4/flask-upload_811c59d1191c4976a8cb3ac2017a1131/setup.py", line 56, in
version=read_version('flask_upload/init.py'),
File "/tmp/pip-install-hq1ysap4/flask-upload_811c59d1191c4976a8cb3ac2017a1131/setup.py", line 49, in read_version
result = re.search(r'^version\s*=\s*'"['"]',
File "/usr/lib/python3.9/re.py", line 201, in search
return _compile(pattern, flags).search(string)
TypeError: cannot use a string pattern on a bytes-like object
----------------------------------------
`

validation failing for pdf files

I have the following in my forms file...

class FileFolderItem(FlaskForm):
	file_ = FileField('', validators=[FileRequired(), FileAllowed(cfiles, 'nope')])
	desc = TextAreaField('Description:')
	submititem = SubmitField('Submit')

when I use this line in my app factory, I am able to upload pdf files...
cfiles = UploadSet('CFILES', ('pdf',))

when I user this line, I am not...
cfiles = UploadSet('CFILES', DOCUMENTS)

with that last line, I am able to upload doc or xls files

Patch for import error

Hi, I have python 3.10 and this error append everytime i start the script. I fixed it by changing 2 lines of code in flask_uploads.py. Here's my version of Flask/Werkzeug/Flask-Uploads :
Name: Werkzeug Name: Flask Name: Flask-Uploads
Version: 3.0.3 Version: 3.0.3 Version: 0.2.1
Idk how to make pull requests so i put the code to modify here :
Replace in flask-uplads.py at line 26 :
from werkzeug import secure_filename, FileStorage
by :
try:
from werkzeug import secure_filename, FileStorage
except ImportError:
from werkzeug.utils import secure_filename
from werkzeug.datastructures.file_storage import FileStorage

Can't use any filetype preset other IMAGES

Versions:
click 6.7
Flask 0.12.1
Flask-Autodoc 0.1.2
Flask-HTTPAuth 3.2.3
Flask-SQLAlchemy 2.2
Flask-Uploads 0.2.1
itsdangerous 0.24
Jinja2 2.9.6
MarkupSafe 1.0
passlib 1.7.1
Pillow 5.1.0
pip 10.0.1
pkg-resources 0.0.0
psycopg2 2.7.4
psycopg2-binary 2.7.4
setuptools 39.0.1
SQLAlchemy 1.1.11
Werkzeug 0.12.2
wheel 0.31.0

With IMAGES:
`app.config['UPLOADED_ACTIMG_ALLOW'] = 'IMAGES'
app.config['UPLOADED_ACTIMG_DEST'] = '/home/flask/ADB/test_02/actimg'
app.config['UPLOADED_EXTIMG_DEST'] = '/home/flask/ADB/test_02/extimg'
db = SQLAlchemy(app)
auth = HTTPBasicAuth()

act_img = UploadSet('actimg')
ext_img = UploadSet('extimg')
configure_uploads(app, (act_img, ext_img))
10.0.0.141 - - [10/May/2018 20:59:16] "POST /api/activity/set_img HTTP/1.1" 201 -`

WITH ALL:
`app.config['UPLOADED_ACTIMG_ALLOW'] = 'ALL'
app.config['UPLOADED_ACTIMG_DEST'] = '/home/flask/ADB/test_02/actimg'
app.config['UPLOADED_EXTIMG_DEST'] = '/home/flask/ADB/test_02/extimg'
db = SQLAlchemy(app)
auth = HTTPBasicAuth()

act_img = UploadSet('actimg')
ext_img = UploadSet('extimg')
configure_uploads(app, (act_img, ext_img))`

File "/home/flask/ADB/test_02/venv/lib/python3.5/site-packages/flask_uploads.py", line 415, in save raise UploadNotAllowed() flask_uploads.UploadNotAllowed 10.0.0.141 - - [10/May/2018 21:02:06] "POST /api/bill/set_img HTTP/1.1" 500 -

Per blueprint configuration

I have an app with multiple blueprints. Is there a way to have an independent configuration for each blueprint?

store filese out side of project folder....

What is the correct way set default folder out side of project root to store files...
I have also have a requirement to store multiple type of files ex: video, images and audio....

want to store each file type to different location out side of project root folder...

I want to have static files outside the project because other project/services are also using the same static files. hence we want to have one common place.

Need a way to override the function that generates the file name.

I can't find anything related to this in the docs except this:

The default implementation splits the name and extension and adds a suffix to the name consisting of an underscore and a number, and tries that until it finds one that doesn’t exist.

under resolve_conflict section.

. Is there a way to do this?

Version conflict with, needs updating in python repositories.

An issue which was fixed needs to be updated in the python repositories.

from werkzeug import secure_filename,FileStorage
changed to

from werkzeug.utils import secure_filename
from werkzeug.datastructures import  FileStorage

Was already fixed in this repository, but not push to pip.

As a temporary solution i use -e git://github.com/maxcountryman/flask-uploads.git#egg=elasticutils in the requirements.txt file.

https://stackoverflow.com/questions/61628503/flask-uploads-importerror-cannot-import-name-secure-filename

A reasonable way to handle with different upload_path and serve_path

The project structure

app/
  __init__.py
config.py
manage.py

I create an UploadSet in app/__init__.py

photos = UploadSet('photos', IMAGES)

When I set UPLOADS_DEFAULT_DEST = 'app/uploads/', the photos will save at app/uploads

but when I visit http://localhost/_uploads/photos/bg.jpg,

FileNotFoundError: [Errno 2] No such file or directory: '/Users/tianyizhuang/Projects/CamusKit.Backend/app/app/uploads/photos/bg.jpg'

An extra app in the path.

What's the reasonable way to deal with the problem?

Remove Module from imports

I updated a project of mine to Flask 0.11 and I noticed that I could not start the development server. It failed with the following error:

ImportError: cannot import name 'Module'

and it was due to this line in flask_uploads.py:

from flask import current_app, Module, send_from_directory, abort, url_for

Module has been deprecated for a long time now and apparently has been removed completely in 0.11. As far as I can see you are not making use of that anywhere and by just removing it I can run the application just fine.

Please consider removing this unused import since it seems like it's a really minor fix.

Maintained?

@maxcountryman First, Thank you for the excellent plugin.

I was planning to use this extension instead of rolling out my own but I noticed numerous open PRs and open issues. Is this repo still maintained?

upload return url is not working when I am saving the pic in multiples destination

I am using flask dropzone along with flask_uploads.
here is my upload func
@current_user_dashboard_view.route('/upload_post_photo', methods=['POST']) @login_required def upload_post_photo(): current_app.config['UPLOADED_PHOTOS_DEST'] = os.getcwd() + '/static/assets/users_assets/' + str( current_user.id) photos = UploadSet('photos', IMAGES) configure_uploads(current_app, photos) patch_request_class(current_app) if "file_urls" not in session: session['file_urls'] = [] file_urls = session['file_urls'] if request.method == 'POST': file_obj = request.files if file_obj is None: print('File obj is none') for f in file_obj: file = request.files.get(f) filename = photos.save( file, name=file.filename ) file_urls.append(photos.url(filename)) session['file_urls'] = file_urls return 'Pic is uploading' return 'Pic is uploading'

I have initialize the upload in my init file and overriding it in upload_post_photo route. cause I want to store the image based on logged in user folder. photos are storing correctly and using the session variable I am storing it in my database.
sample pic access url
http://127.0.0.1:5001/_uploads/photos/mlogo_1.png

but when I am trying to view it sometime the this access url doesn't work sporadically.

note : I have save the content in a single folder this issue is not happening. not sure what is happening

importError: cannot import name Module

when using flask-uploads, the following is occurred.
(for security problem, I removed folder names of my project with xxxx)
Also, I am using Flask 0.11.dev.

Could you please investigate this issue ? Maybe... "Module" could be removed or not ?

  File "/Users/xxxx/venv/xxxx/lib/python2.7/site-packages/flask/exthook.py", line 81, in load_module
    reraise(exc_type, exc_value, tb.tb_next)
  File "/Users/xxxx/venv/xxxx/lib/python2.7/site-packages/flask_uploads.py", line 24, in <module>
    from flask import current_app, Module, send_from_directory, abort, url_for
ImportError: cannot import name Module

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.