I'm using flask to make a web to upload videos, adding a video worked but when I try to edit(replace) the video I uploaded, there's a AttributeError: 'SpooledTemporaryFile' object has no attribute 'replace'
In forms.py, url as the route of the video:
url = FileField(
label="Video",
validators=[
Optional()
],
description="Video"
In views,py:
def movie_edit(id=None):
form = MovieForm()
form.url.validators = []
movie = Movie.query.get_or_404(int(id))
if form.validate_on_submit():
data = form.data
if not os.path.exists(app.config["UP_DIR"]):
os.makedirs(app.config["UP_DIR"])
os.chmod(app.config["UP_DIR"], "rw")
if data["url"] != "":
file_url = secure_filename(data["url"])
movie.url = change_filename(file_url)
form.url.data.save(app.config["UP_DIR"] + movie.url)
How to fix this error?
I'm guessing that data["url"] is a SpooledTemporaryFile object, not a string. Without the full stacktrace, I can't tell which line is barfing, but you probably need to change file_url = secure_filename(data["url"]) to file_url = secure_filename(data["url"].filename) or something similar.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With