Skip to content

Commit e8bc62e

Browse files
committed
add new implementation using httpx storage client
1 parent 85a0081 commit e8bc62e

File tree

2 files changed

+7
-44
lines changed
  • services/api-server/src/simcore_service_api_server

2 files changed

+7
-44
lines changed

services/api-server/src/simcore_service_api_server/api/routes/files.py

Lines changed: 6 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
from typing import IO, Annotated, Any, Final
66
from uuid import UUID
77

8-
from aiohttp import ClientSession, ClientTimeout, TCPConnector
9-
from common_library.error_codes import create_error_code
108
from fastapi import APIRouter, Body, Depends
119
from fastapi import File as FileParam
1210
from fastapi import Header, Request, UploadFile, status
@@ -15,23 +13,18 @@
1513
from models_library.api_schemas_storage.storage_schemas import (
1614
ETag,
1715
FileUploadCompletionBody,
18-
LinkType,
1916
)
2017
from models_library.basic_types import SHA256Str
2118
from models_library.projects_nodes_io import NodeID
22-
from pydantic import AnyUrl, ByteSize, PositiveInt, TypeAdapter, ValidationError
23-
from servicelib.aiohttp import client_session
19+
from pydantic import AnyUrl, PositiveInt, TypeAdapter, ValidationError
2420
from servicelib.fastapi.requests_decorators import cancel_on_disconnect
25-
from servicelib.logging_errors import create_troubleshotting_log_kwargs
2621
from simcore_sdk.node_ports_common.constants import SIMCORE_LOCATION
27-
from simcore_sdk.node_ports_common.exceptions import StorageServerIssue
2822
from simcore_sdk.node_ports_common.file_io_utils import UploadableFileObject
2923
from simcore_sdk.node_ports_common.filemanager import (
3024
UploadedFile,
3125
UploadedFolder,
3226
abort_upload,
3327
complete_file_upload,
34-
get_upload_links_from_s3,
3528
)
3629
from simcore_sdk.node_ports_common.filemanager import upload_path as storage_upload_path
3730
from starlette.datastructures import URL
@@ -304,48 +297,18 @@ async def get_upload_links(
304297
client_file: UserFileToProgramJob | UserFile,
305298
user_id: Annotated[PositiveInt, Depends(get_current_user_id)],
306299
webserver_api: Annotated[AuthSession, Depends(get_webserver_session)],
300+
storage_client: Annotated[StorageApi, Depends(get_api_client(StorageApi))],
307301
):
308302
"""Get upload links for uploading a file to storage"""
309303
assert request # nosec
310304
file_meta = await _create_domain_file(
311305
webserver_api=webserver_api, file_id=None, client_file=client_file
312306
)
313307

314-
try:
315-
async with ClientSession(
316-
connector=TCPConnector(force_close=True),
317-
timeout=ClientTimeout(
318-
total=_AIOHTTP_CLIENT_SESSION_TIMEOUT_SECONDS,
319-
connect=_AIOHTTP_CLIENT_SESSION_TIMEOUT_SECONDS,
320-
sock_connect=_AIOHTTP_CLIENT_SESSION_TIMEOUT_SECONDS,
321-
sock_read=_AIOHTTP_CLIENT_SESSION_TIMEOUT_SECONDS,
322-
),
323-
) as client_session:
324-
_, upload_links = await get_upload_links_from_s3(
325-
user_id=user_id,
326-
store_name=None,
327-
store_id=SIMCORE_LOCATION,
328-
s3_object=file_meta.storage_file_id,
329-
client_session=client_session,
330-
link_type=LinkType.PRESIGNED,
331-
file_size=ByteSize(client_file.filesize),
332-
is_directory=False,
333-
sha256_checksum=file_meta.sha256_checksum,
334-
)
335-
except StorageServerIssue as exc:
336-
error_code = create_error_code(exc)
337-
msg = f"Request to storage service timed out [{error_code}]"
338-
status_code = status.HTTP_504_GATEWAY_TIMEOUT
339-
340-
_logger.exception(
341-
**create_troubleshotting_log_kwargs(
342-
msg,
343-
error=exc,
344-
error_code=error_code,
345-
tip="Check if storage service is healthy",
346-
)
347-
)
348-
raise HTTPException(status_code=status_code, detail=msg) from exc
308+
upload_links = await storage_client.get_file_upload_links(
309+
user_id=user_id, file=file_meta, client_file=client_file
310+
)
311+
349312
completion_url: URL = request.url_for(
350313
"complete_multipart_upload", file_id=file_meta.id
351314
)

services/api-server/src/simcore_service_api_server/services_http/storage.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ async def get_file_upload_links(
169169
"link_type": LinkType.PRESIGNED.value,
170170
"file_size": int(client_file.filesize),
171171
"is_directory": "false",
172-
"sha256_checksum": client_file.sha256_checksum,
172+
"sha256_checksum": f"{client_file.sha256_checksum}",
173173
}
174174

175175
# complete_upload_file

0 commit comments

Comments
 (0)