diff --git a/src/aleph/web/controllers/ipfs.py b/src/aleph/web/controllers/ipfs.py index 1d63fb22f..65d5ea24f 100644 --- a/src/aleph/web/controllers/ipfs.py +++ b/src/aleph/web/controllers/ipfs.py @@ -53,9 +53,10 @@ async def ipfs_add_file(request: web.Request): # IPFS add returns the cumulative size and not the real file size. # We need the real file size here. + # Use pinning_client to stat the file since that's where it was added. try: stats = await asyncio.wait_for( - ipfs_service.ipfs_client.files.stat(f"/ipfs/{cid}"), + ipfs_service.pinning_client.files.stat(f"/ipfs/{cid}"), config.ipfs.stat_timeout.value, ) size = stats["Size"] diff --git a/tests/api/test_storage.py b/tests/api/test_storage.py index 0e15de67e..d9515bee0 100644 --- a/tests/api/test_storage.py +++ b/tests/api/test_storage.py @@ -83,6 +83,15 @@ async def api_client(ccn_test_aiohttp_app, mocker, aiohttp_client): "Type": "file", } ) + ipfs_service.pinning_client.files.stat = mocker.AsyncMock( + return_value={ + "Hash": EXPECTED_FILE_CID, + "Size": 34, + "CumulativeSize": 42, + "Blocks": 0, + "Type": "file", + } + ) ccn_test_aiohttp_app[APP_STATE_STORAGE_SERVICE] = StorageService( storage_engine=InMemoryStorageEngine(files={}),