peterhartwigCF commited on
Commit
cfe4480
·
verified ·
1 Parent(s): b848093

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -15
app.py CHANGED
@@ -1,8 +1,9 @@
1
  from fastapi import FastAPI, File, UploadFile
2
- import logging
 
 
 
3
 
4
- logger = logging.getLogger('uvicorn.error')
5
- logger.setLevel(logging.DEBUG)
6
  app = FastAPI()
7
 
8
  @app.get("/")
@@ -14,15 +15,16 @@ def greet_json():
14
  def make_versions():
15
  return("making versions")
16
 
17
- @app.post("/upload/")
18
- async def upload_file(file: UploadFile = File(...)):
19
- content = await file.read()
20
-
21
- # Print information about the file to the console
22
- logger.debug(f"File Name: {file.filename}")
23
- logger.debug(f"File Size: {len(content)}")
24
- logger.debug(f"File MIME Type: {file.content_type}")
25
-
26
- # Return information about the file to the caller - note that the
27
- # content_type can easily be spoofed
28
- return {"filename": file.filename, "file_size": len(content), "file_mime_type": file.content_type}
 
 
1
  from fastapi import FastAPI, File, UploadFile
2
+ import httpx
3
+ from fastapi.responses import JSONResponse
4
+ from io import BytesIO
5
+
6
 
 
 
7
  app = FastAPI()
8
 
9
  @app.get("/")
 
15
  def make_versions():
16
  return("making versions")
17
 
18
+ # Replace with your target external API URL
19
+ EXTERNAL_API_URL = "https://external-api.example.com/process"
20
+
21
+ @app.post("/send-image")
22
+ async def send_image(image: UploadFile = File(...)):
23
+ # Read image data
24
+ image_bytes = await image.read()
25
+
26
+ # Optional: prepare image payload for external API
27
+ files = {"file": (image.filename, BytesIO(image_bytes), image.content_type)}
28
+
29
+ # Call external API
30
+ return(f"image uploaded {files}")