Publish #1
@@ -54,7 +54,7 @@ uploadForm.addEventListener('submit', async (event) => {
|
||||
setStatus('Загрузка...', '');
|
||||
|
||||
try {
|
||||
const response = await fetch('http://192.168.0.132:5000/upload_file', {
|
||||
const response = await fetch('/upload_file', {
|
||||
method: 'POST',
|
||||
body: formData
|
||||
});
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
from fastapi import FastAPI, File, UploadFile
|
||||
from fastapi.staticfiles import StaticFiles
|
||||
|
||||
import dotenv
|
||||
import os
|
||||
|
||||
import asyncio
|
||||
import uvicorn
|
||||
|
||||
dotenv.load_dotenv()
|
||||
disable_docs = os.getenv("DISABLE_DOCS", "true").lower() == "true"
|
||||
app: FastAPI = FastAPI(title="DropMeFiles analog")
|
||||
# app: FastAPI = FastAPI(title="DropMeFiles analog",
|
||||
# summary="OpenAPI schema for \"DropMeFiles analog\" project!",
|
||||
# version="0.1",
|
||||
# contact={"GitHub": "https://github.com/IgorVolochay/Drop-me-files-analog"},
|
||||
# docs_url=None if disable_docs else "/docs",
|
||||
# redoc_url=None if disable_docs else "/redoc",
|
||||
# openapi_url=None if disable_docs else "/openapi.json")
|
||||
|
||||
# app.mount("/", StaticFiles(directory="frontend", html=True), name="frontend")
|
||||
|
||||
@app.post("/upload_file")
|
||||
async def create_upload_file(file: UploadFile = File(...)):
|
||||
return {"filename": file.filename, "content_type": file.content_type}
|
||||
|
||||
async def main():
|
||||
config = uvicorn.Config("main:app", port=5000, host="0.0.0.0", log_level="debug")
|
||||
server = uvicorn.Server(config)
|
||||
await server.serve()
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
@@ -1,49 +0,0 @@
|
||||
from fastapi import FastAPI, File, UploadFile
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
|
||||
from typing import Annotated
|
||||
|
||||
import dotenv
|
||||
import os
|
||||
|
||||
import asyncio
|
||||
import uvicorn
|
||||
|
||||
|
||||
dotenv.load_dotenv()
|
||||
disable_docs = os.getenv("DISABLE_DOCS", "true").lower() == "true"
|
||||
app: FastAPI = FastAPI(title="This OR That",
|
||||
summary="OpenAPI schema for \"This OR That\" project!",
|
||||
version="0.1",
|
||||
contact={"GitHub": "https://github.com/IgorVolochay/thisORthat"},
|
||||
docs_url=None if disable_docs else "/docs",
|
||||
redoc_url=None if disable_docs else "/redoc",
|
||||
openapi_url=None if disable_docs else "/openapi.json")
|
||||
|
||||
|
||||
origins = ["*"]
|
||||
|
||||
app.add_middleware(
|
||||
CORSMiddleware,
|
||||
allow_origins=origins,
|
||||
allow_credentials=True,
|
||||
allow_methods=["*"],
|
||||
allow_headers=["*"],
|
||||
)
|
||||
|
||||
@app.get("/")
|
||||
def root():
|
||||
return "Hello!"
|
||||
|
||||
@app.post("/upload_file")
|
||||
@app.post("/upload_file")
|
||||
async def create_file(file: Annotated[bytes, File()]):
|
||||
return {"file_size": len(file)}
|
||||
|
||||
async def main():
|
||||
config = uvicorn.Config("main:app", port=5000, log_level="debug")
|
||||
server = uvicorn.Server(config)
|
||||
await server.serve()
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
Reference in New Issue
Block a user