Shakauthossain-NH commited on
Commit
268c8ca
·
verified ·
1 Parent(s): 2b723b8

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +8 -4
main.py CHANGED
@@ -146,7 +146,6 @@ def insert_cover_image_to_docx(docx_bytes: bytes, image_bytes: bytes) -> BytesIO
146
 
147
 
148
  # === API 2: Merge Cover Image with DOCX ===
149
-
150
  @app.post("/merge-cover-docx")
151
  async def merge_cover_docx(
152
  cover_image: UploadFile = File(...),
@@ -156,8 +155,14 @@ async def merge_cover_docx(
156
  cover_bytes = await cover_image.read()
157
  docx_bytes = await docx_file.read()
158
 
159
- if not cover_bytes or not docx_bytes:
160
- raise ValueError("One or both uploaded files are empty.")
 
 
 
 
 
 
161
 
162
  output_stream = insert_cover_image_to_docx(docx_bytes, cover_bytes)
163
 
@@ -168,4 +173,3 @@ async def merge_cover_docx(
168
  )
169
  except Exception as e:
170
  return JSONResponse(status_code=500, content={"error": str(e)})
171
-
 
146
 
147
 
148
  # === API 2: Merge Cover Image with DOCX ===
 
149
  @app.post("/merge-cover-docx")
150
  async def merge_cover_docx(
151
  cover_image: UploadFile = File(...),
 
155
  cover_bytes = await cover_image.read()
156
  docx_bytes = await docx_file.read()
157
 
158
+ if not cover_bytes or not isinstance(cover_bytes, bytes):
159
+ raise ValueError("Cover image is empty or invalid.")
160
+ if not docx_bytes or not isinstance(docx_bytes, bytes):
161
+ raise ValueError("DOCX file is empty or invalid.")
162
+
163
+ # Log file sizes (optional for debugging)
164
+ print(f"[INFO] Received image: {len(cover_bytes)} bytes")
165
+ print(f"[INFO] Received docx: {len(docx_bytes)} bytes")
166
 
167
  output_stream = insert_cover_image_to_docx(docx_bytes, cover_bytes)
168
 
 
173
  )
174
  except Exception as e:
175
  return JSONResponse(status_code=500, content={"error": str(e)})