|
5 | 5 | from typing import IO, Annotated, Any, Final |
6 | 6 | from uuid import UUID |
7 | 7 |
|
8 | | -from aiohttp import ClientSession, ClientTimeout, TCPConnector |
9 | | -from common_library.error_codes import create_error_code |
10 | 8 | from fastapi import APIRouter, Body, Depends |
11 | 9 | from fastapi import File as FileParam |
12 | 10 | from fastapi import Header, Request, UploadFile, status |
|
15 | 13 | from models_library.api_schemas_storage.storage_schemas import ( |
16 | 14 | ETag, |
17 | 15 | FileUploadCompletionBody, |
18 | | - LinkType, |
19 | 16 | ) |
20 | 17 | from models_library.basic_types import SHA256Str |
21 | 18 | 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 |
24 | 20 | from servicelib.fastapi.requests_decorators import cancel_on_disconnect |
25 | | -from servicelib.logging_errors import create_troubleshotting_log_kwargs |
26 | 21 | from simcore_sdk.node_ports_common.constants import SIMCORE_LOCATION |
27 | | -from simcore_sdk.node_ports_common.exceptions import StorageServerIssue |
28 | 22 | from simcore_sdk.node_ports_common.file_io_utils import UploadableFileObject |
29 | 23 | from simcore_sdk.node_ports_common.filemanager import ( |
30 | 24 | UploadedFile, |
31 | 25 | UploadedFolder, |
32 | 26 | abort_upload, |
33 | 27 | complete_file_upload, |
34 | | - get_upload_links_from_s3, |
35 | 28 | ) |
36 | 29 | from simcore_sdk.node_ports_common.filemanager import upload_path as storage_upload_path |
37 | 30 | from starlette.datastructures import URL |
@@ -304,48 +297,18 @@ async def get_upload_links( |
304 | 297 | client_file: UserFileToProgramJob | UserFile, |
305 | 298 | user_id: Annotated[PositiveInt, Depends(get_current_user_id)], |
306 | 299 | webserver_api: Annotated[AuthSession, Depends(get_webserver_session)], |
| 300 | + storage_client: Annotated[StorageApi, Depends(get_api_client(StorageApi))], |
307 | 301 | ): |
308 | 302 | """Get upload links for uploading a file to storage""" |
309 | 303 | assert request # nosec |
310 | 304 | file_meta = await _create_domain_file( |
311 | 305 | webserver_api=webserver_api, file_id=None, client_file=client_file |
312 | 306 | ) |
313 | 307 |
|
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 | + |
349 | 312 | completion_url: URL = request.url_for( |
350 | 313 | "complete_multipart_upload", file_id=file_meta.id |
351 | 314 | ) |
|
0 commit comments