TaleLin / lin-cms-flask

🎀A simple and practical CMS implememted by Flask
http://doc.cms.talelin.com/
Other
832 stars 216 forks source link

OSS插件中:`多图上传` 如果由于网络波动问题 `有图片上传不成功` 不需要处理或者提示嘛? #137

Closed hezygo closed 2 years ago

hezygo commented 3 years ago

请详细描述您对本项目的任何问题,我们会在第一时间查阅和解决。

`@api.route("/upload_multiple", methods=["POST"])

def upload_multiple_to_ali():

imgs = []

for item in request.files:

    img = request.files.get(item, None)

    if not img:

        raise ParameterError("没接收到图片,请检查图片路径")

    if img and allowed_file(img.filename):

        url = upload_image_bytes(img.filename, img)

        if url:

            # 每上传成功一次图片需记录到数据库

            with db.auto_commit():

                exist = OSS.get(url=url)

                if not exist:

                    data = {"url": url}

                    res = OSS.create(**data)

                    db.session.flush()

                    imgs.append({"key": item, "url": url, "id": res.id})

                else:

                    imgs.append({"key": item, "url": url, "id": exist.id})

       #此处是否应该把上传失败的图片名称 添加到imgs的列表里面

return jsonify(imgs)`
sunlin92 commented 3 years ago

感谢反馈,我们会讨论这个问题是否有合适的通用方案