flask-file-upload: 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?
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 19 (12 by maintainers)
Commits related to this issue
- Wrong path when deleting files #46 — committed to joegasewicz/flask-file-upload by joegasewicz 4 years ago
- Wrong path when deleting files #46 - fixes multiple session creation — committed to joegasewicz/flask-file-upload by joegasewicz 4 years ago
- Wrong path when deleting files #46 - fixes multiple session creation — committed to joegasewicz/flask-file-upload by joegasewicz 4 years ago
- Wrong path when deleting files #46 - fixes multiple session creation — committed to joegasewicz/flask-file-upload by joegasewicz 4 years ago
- Wrong path when deleting files #46 - fixes multiple session creation — committed to joegasewicz/flask-file-upload by joegasewicz 4 years ago
- Wrong path when deleting files #46 - fixes multiple session creation — committed to joegasewicz/flask-file-upload by joegasewicz 4 years ago
- Merge pull request #52 from joegasewicz/issue_46 Wrong path when deleting files #46 — committed to joegasewicz/flask-file-upload by joegasewicz 4 years ago
Thanks, I’ll continue there.
It’s so close! It’s only 1 directory off now. It’s doing /static/device/4/binder.png, but the file is saved at /static/uploads/device/4/binder.png.
Thanks! I’m sorry if my email notifications are bothering you at a late hour. I really like this library, it makes it so easy to upload files with flask sqlalchemy. So thank you and your contributors for this work.