TypeError:存储必须是werkzeug.FileStorage

时间:2019-07-09 11:32:26

标签: python flask werkzeug file-storage

我正在尝试在Flask应用程序的文件系统中保存图像。工作正常。我可以上传照片并检索它们。但是,当我单击“提交”而不选择任何图像时,它给我一个错误:

  

TypeError:存储空间必须是werkzeug.FileStorage。

请帮忙!!

我的经验很少,所以我不在这里。错误来自flask_uploads.py:

  

def save(自身,存储,文件夹=无,名称=无):           “”           这样会将werkzeug.FileStorage保存到该上传集中。如果           不允许上传,将引发UploadNotAllowed错误。           否则,将保存文件及其名称(包括文件夹)           将返回。

    :param storage: The uploaded file to save.
    :param folder: The subfolder within the upload set to save to.
    :param name: The name to save the file as. If it ends with a dot, the
                 file's extension will be appended to the end. (If you
                 are using `name`, you can include the folder in the
                 `name` instead of explicitly using `folder`, i.e.
                 ``uset.save(file, name="someguy/photo_123.")``
    """
    if not isinstance(storage, FileStorage):
        raise TypeError("storage must be a werkzeug.FileStorage")

从flask_uploads导入UploadSet,configure_uploads,IMAGES

form =添加***()

if form.validate_on_submit():
    image_url = photos.url(photos.save(form.image.data))  
    new_**** = ****(screenname= form.screenname.data, fullname = form.fullname.data, team = form.team.data, image=image_url)


db.session.add(new_****)
    db.session.commit()
    flash("Added Successfully")
    return redirect (url_for('****'))

return render_template("****.html", form=form)

如果未选择图片,我希望html返回页面。

0 个答案:

没有答案