upload.py 968 B

12345678910111213141516171819202122232425
  1. from fastapi import FastAPI, File, UploadFile
  2. from pathlib import Path
  3. app = FastAPI()
  4. #curl 'http://127.0.0.1:8000/pushUpdate/dev/0.1/linux -H 'accept: application/json' -H 'Content-Type: multipart/form-data' -F 'file=@updatefile.yml'
  5. @app.post("/pushUpdate/{branch}/{version}/{os}")
  6. async def push_update(file: UploadFile, branch: str,version: str,os: str):
  7. nfile = Path(f'{branch}/{version}/{os}/{file.filename}')
  8. nfile.parent.mkdir(parents=True, exist_ok=True)
  9. print(f'{branch}/{version}/{os}/{file.filename}')
  10. with open(f'{branch}/{version}/{os}/{file.filename}',"w") as f :
  11. content = await file.read()
  12. f.write(content.decode())
  13. f.close()
  14. return {"filename": file.filename}
  15. @app.post("/uploadfile/")
  16. async def create_upload_file(file: UploadFile):
  17. with open(file.filename,"w") as f :
  18. content = await file.read()
  19. f.write(content.decode())
  20. f.close()
  21. return {"filename": file.filename}