Giter Club home page Giter Club logo

flask-file-upload's People

Contributors

dependabot[bot] avatar formerlychucks avatar joegasewicz avatar ondralukes avatar ujjwalbe 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

flask-file-upload's Issues

Delete files only method

Delete files only method would be more useful when the user wants to drop a row from the db containing the file data but afterwards needs to cleanup the files from the server.

`save_files` should add updates to session

save_files should add updates to session as we require the primary key value for directory path on the server.
Perhaps the api could have an option set as default to auto commit, if False then let the user commit first manually.

Wrong path when deleting files

I'm not able to delete files due to the filename not being correct. It's showing as image.image/png but the real file I uploaded is called 'binder.png'. I use 'image' on the form as name='image' as well as in the model file and the dict when saving the file originally.

I updated my config to:

UPLOAD_FOLDER = Path.cwd().joinpath("smartHomeDevicesForDisabled", "smartify", "static", "uploads")

The error I'm getting when trying to delete:

INFO in routes: Device could not be deleted.
[2020-01-01 18:22:24,918] INFO in routes: [Errno 2] No such file or directory: '/home/laurin/Projects/smartHomeDevicesForDisabled/smartify/static/uploads/device/7/image.image/png'

How I'm trying to delete:

def deleteDevice(id):
	try: 
		device = Device.query.get(id)
		file_upload.delete_files(device, db=db, files=["image"])
		db.session.delete(device)
		db.session.commit() 
		flash('Device successfully deleted.', 'success')
		app.logger.info('Device deleted.')
	except Exception as e: 
		flash('Device could not be deleted.', 'danger')
		app.logger.info('Device could not be deleted.')
		app.logger.info(e)
	
	return redirect(url_for('editDevices'))

How I'm originally saving the files:

device = Device(name=form.name.data, 
			description=form.description.data, 
			price=form.price.data,
			recurring_price=form.recurring_price.data,
			payment_occurence_id=po.id, 
			link=form.link.data,
			category_id=dc.id, 
			rating=form.rating.data,
			narrative=form.narrative.data
			)
image = request.files["image"]
device = file_upload.save_files(device, files={
	"image": image
})

Is this a bug or am I doing something wrong?

Update Model Clean Up public method

Add a update_model_clean_up public method.
The idea is that if the files on the server are updated or removed but for any reason the model didn't get updated the user can evoke this method in a try except block.

update_model_clean_up will go and look in the dir related to the filenames, check to see if the name has been changed or the files no longer exist and then updated the model and commit the session.

 file_upload.update_model_clean_up(your_model, filenames=["my_video", "placeholder"])

File Url paths

File Url paths

file_upload.get_file_url(blog_post, filename="placeholder_img")

Option to define primary key(s)

We currently only have the standard / default id representing a model's primary key. We should add an options when using our Api's model decorator:

   @file_upload.Model(primary_key="user_id")
   class ModelTest(db.Model):
       ...
       my_placeholder = file_upload.Column(db)
       my_video = file_upload.Column(db)

OR

   @file_upload.Model
   class ModelTest(db.Model):
       ...
       my_placeholder = file_upload.Column(db, primary_key="user_id") 
       my_video = file_upload.Column(db) # We only need to define once on a model

Rollback for `save_files`

Rollback for save_files method. If there is an exception commiting the changes of the model to the db, then the user of this library should be able to undo the changes made to files on the server.

Update Files Clean Up public method

Add a update_files_clean_up public method.
The idea is that if the model / table gets updated or removed but for any reason the files didn't get updated / removed.

update_files_clean_up will check that the files are in sync with the current model state. If not, then the changes will be carried out on the files on the server to reflect the changes on the model. If the changes cannot be fixed then a warning should be logged

 file_upload.update_files_clean_up(your_model, filenames={"my_video":  my_video})

Add index to readme

Add a method index (quick links FFU methods) t the top of the read me so users dont have to scroll all the way down to read a specific methods docs.

Update file name

Update file name

file_upload.update_file_name(BlogPostModel, my_video, new_filename="new_name")

Tests break when forking project

Currently the tests rely on 2 media files. the tests/test_path/blogs/1/my_placeholder.png is missing though.

Needs to check why this file isn't in this location on test set up.

Update files

Update files etc.

   file_upload.update_files(BlogPostModel, files=[my_video])

> So does that set the file size or the filename size? Because I can upload the image 'binder.png':

So does that set the file size or the filename size? Because I can upload the image 'binder.png':
binder

And it works great. But if I try to upload '8percenttrimmed_heightmap.png':
8percenttrimmed_heightmap
It gives me the error:
(pymysql.err.DataError) (1406, "Data too long for column 'image__file_name' at row 1")

And to test it I changed the config to be:
MAX_CONTENT_LENGTH = 1000 * 1000 * 1024 * 1024

can you past the actual file name . this is actually a MySQL error saying that the string we save in the image__file_name column is too long..

Originally posted by @joegasewicz in #46 (comment)

Make it easier to add file url paths to SQLAlchemy models

This issue will resolve appending the relative file urls to entities with one to many relations, specifically relational back references where file metadata is present.

The Api will look like:

            blogs = add_file_urls_to_models(
                blogs,
                filename="blog_image",
                backref={
                    "name": "blog_news",
                    "filename": "blog_news_image",
                }
            )

Configuration Documentation

Explain how the configuration can be set up without passing in all kwargs as these can be assigned to app.config and we can just pass app to FileUpload()

Create a single source when working with the session

The work to do with working with the session needs to be consolidated to a single or method. This is because there still exists session logic that is not referencing the current session (it must call object_session:

https://github.com/joegasewicz/Flask-File-Upload/blob/62c689fcc7ecebccdef9749ae61c1960b4ceda5d/flask_file_upload/file_upload.py#L193

So to fix this issue , create a method in model utils class, and move any session logic from Fileupload class to this single point with a unit test(s).

Linting

Add & configure Pylint to this repo.

MySQL compatibility

sqlalchemy is giving me:

VARCHAR requires a length on dialect mysql

I'm assuming it is as simple as adding a length when connecting to flask sql alchemy. Could you please put this in a release soon?

Saving Uploaded Image to Server

Hello again, you fixed compatibility with MySQL - thanks!

However I am having a new problem. I believe I'm almost to a fully working solution with this last hurdle. The error I'm getting is:

INFO in routes: [FLASK_FILE_UPLOAD_ERROR]: Couldn't create file path: /static/uploads/device/9/binder.png

My configuration is:
UPLOAD_FOLDER = '/static/uploads'
ALLOWED_EXTENSIONS = ["jpg", "png"]
MAX_CONTENT_LENGTH = 1000 * 1000 * 1024 * 1024

In my models.py:

@file_upload.Model
class Device(db.Model):
    image = file_upload.Column(db)

In my routes.py:

image = request.files["image"]
device = file_upload.save_files(device, files={
	"image": image
})

init.py:

db = SQLAlchemy()
file_upload = FileUpload(db=db)

def create_app():
	#create and configure the app 
	app = Flask(__name__, instance_relative_config=True, 
		template_folder="templates", static_folder="static")
	app.config.from_envvar('APP_CONFIG_FILE')

	db.init_app(app)
	file_upload.init_app(app)	

tox setup

tox set up for Python 3.6, 3.7, 3.8

raw SQLAlchemy compatibility

Currently Flask-FileUpload only interfaces with Flask-SQLAlchemy.

  • To resolve this issue, SQLAlchemy should be compatible with the same public api FFU offers.

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.