MCPcopy Create free account
hub / github.com/IfcOpenShell/IfcOpenShell / upload_part

Function upload_part

src/opencdeserver/api/app/api/documents.py:219–260  ·  view source on GitHub ↗
(part_id: str, request: Request, current_user: User = Depends(get_current_active_user))

Source from the content-addressed store, hash-verified

217
218@router.post("/documents/1.0/upload-part/{part_id}", tags=[""])
219async def upload_part(part_id: str, request: Request, current_user: User = Depends(get_current_active_user)):
220
221 # file_name = doc_db.safe_path(part_id)
222 file_name = part_id
223
224 # see if the user really has the part-node in the database, before receiving upload of this part
225 # and get the document_id of the part
226 document = doc_db.user_has_part(part_id, current_user)
227
228 request_body = await request.body()
229
230 if document:
231
232 # try to receive the uploaded part
233 try:
234 print("File contents: ", request_body)
235
236 # use document_id instead as dir_name
237 # dir_name = doc_db.safe_path(document.document_id)
238 dir_name = document.document_id
239
240 path = "./data/document_parts/" + dir_name + "/"
241
242 if not os.path.exists(path):
243 os.makedirs(path)
244
245 with open(path + file_name, "wb") as f:
246 f.write(request_body)
247
248 except Exception:
249 print("Error uploading file")
250 print(traceback.format_exc())
251 print("Error uploading file")
252 print(sys.exc_info()[2])
253
254 finally:
255 # We will write to the database, information about part successfully uploaded.
256 doc_db.mark_part_as_uploaded(part_id, current_user)
257
258 doc_db.debug(endpoint="upload-part", request={"part_id": part_id}, response={"uploaded": True})
259
260 return {"message": f"Successfully uploaded part {file_name}"}
261
262
263# ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----

Callers

nothing calls this directly

Calls 6

printFunction · 0.85
user_has_partMethod · 0.80
mark_part_as_uploadedMethod · 0.80
debugMethod · 0.80
openFunction · 0.50
writeMethod · 0.45

Tested by

no test coverage detected