upload_oview.py 1.4 KB
# coding=utf-8
#author:        4N
#createtime:    2021/9/17
#email:         nheweijun@sina.com


from app.util.component.ApiTemplate import ApiTemplate
import os
from flask import request
import uuid
import configure
class Api(ApiTemplate):
    api_name = "上传缩略图"

    def process(self):

        # 返回结果
        res = {}
        try:
            # 业务逻辑
            dir_path = os.path.join(os.path.dirname(os.path.dirname(os.path.realpath(__file__))),"overview")

            file = request.files['file']
            gid = uuid.uuid1().__str__()

            filename = file.filename.split('"')[0]
            store_file = os.path.join(dir_path, "{}{}".format(gid,filename))
            file.save(store_file)

            res["data"] ="http://{}/API/Service/Overview/{}".format(
                    configure.deploy_ip_host, "{}{}".format(gid,filename))
            res["result"] = True
        except Exception as e:
            raise e
        return res

    api_doc = {

        "tags": ["切片服务接口"],
        "parameters": [
            {"name": "file",
             "in": "formData",
             "type": "file",
             "description": "缩略图"},
        ],
        "responses": {
            200: {
                "schema": {
                    "properties": {
                    }
                }
            }
        }
    }