from typing import Union
from pydantic import BaseModel, EmailStr
from fastapi import FastAPI
import threading
import wget
from urllib3 import encode_multipart_formdata
#python通过http上传视频文件
def <函数名>(<参数>):
file = {'<key>': (<filename>, open(<file_path>,'rb').read()), 'fileType':'video/mp4'}
encode_data = encode_multipart_formdata(file)
file_data = encode_data[0]
headers_from_data = {"Content-Type": encode_data[1],}
r=requests.post("<url地址>", headers=headers_from_data, data=file_data)
print(r.json())
app = FastAPI()
class item(BaseModel):
name: str
pic: str
audio: str
@app.post("/post")
def postest(<name_str>: item):
print(<name_str>.name)
filepath = <name_str>.filepath
pic_pth = wget.download(<name_str>.pic, out = <save_dir> + "/source_img.png")
audio_pth = wget.download(<name_str>.audio, out = <save_dir> + "/driven_audio.wav")
thread1 = threading.Thread(target=<函数名>, args = (<函数的参数>))
thread1.start()
return {'code': 200}
postman测试:
uvicorn <文件名>:app --host '0.0.0.0' --port <port>