Skip to content

Commit eff0504

Browse files
authored
fix: ipfs/add_file endpoint failed because of missing name field (#883)
The endpoint returned a 500 error code in all situations because of a missing "Name" field in the response from the IPFS service implementation. This regression was introduced in #859. This commit gets the filename from the multipart upload or hardcodes it to "file" otherwise.
1 parent 3f27e06 commit eff0504

File tree

3 files changed

+6
-17
lines changed

3 files changed

+6
-17
lines changed

src/aleph/services/ipfs/service.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -252,16 +252,6 @@ async def pin_add(self, cid: str, timeout: int = 30, tries: int = 1):
252252
else:
253253
break
254254

255-
async def add_file(self, file_content: bytes) -> Dict[str, str]:
256-
"""
257-
Add a file to IPFS using bytes as data.
258-
259-
This is a backward-compatible wrapper around add_bytes().
260-
Uses the pinning client for write operations.
261-
"""
262-
hash = await self.add_bytes(file_content)
263-
return {"Hash": hash}
264-
265255
async def sub(self, topic: str):
266256
ipfs_client = self.ipfs_client
267257

src/aleph/storage.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,8 +287,7 @@ async def add_file(
287287
self, session: DbSession, file_content: bytes, engine: ItemType = ItemType.ipfs
288288
) -> str:
289289
if engine == ItemType.ipfs:
290-
output = await self.ipfs_service.add_file(file_content)
291-
file_hash = output["Hash"]
290+
file_hash = await self.ipfs_service.add_bytes(file_content)
292291

293292
elif engine == ItemType.storage:
294293
file_hash = sha256(file_content).hexdigest()

src/aleph/web/controllers/ipfs.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,12 @@ async def ipfs_add_file(request: web.Request):
3333
file_content: bytes
3434
if isinstance(file_field, bytes):
3535
file_content = file_field
36+
filename = "file"
3637
elif isinstance(file_field, str):
3738
file_content = file_field.encode()
39+
filename = "file"
3840
elif isinstance(file_field, FileField):
41+
filename = file_field.filename
3942
if file_field.content_type != "application/octet-stream":
4043
raise web.HTTPUnprocessableEntity(
4144
reason="Invalid content-type for 'file' field. Must be 'application/octet-stream'."
@@ -46,10 +49,7 @@ async def ipfs_add_file(request: web.Request):
4649
reason="Invalid type for 'file' field. Must be bytes, str or FileField."
4750
)
4851

49-
ipfs_add_response = await ipfs_service.add_file(file_content)
50-
51-
cid = ipfs_add_response["Hash"]
52-
name = ipfs_add_response["Name"]
52+
cid = await ipfs_service.add_bytes(file_content)
5353

5454
# IPFS add returns the cumulative size and not the real file size.
5555
# We need the real file size here.
@@ -71,7 +71,7 @@ async def ipfs_add_file(request: web.Request):
7171
output = {
7272
"status": "success",
7373
"hash": cid,
74-
"name": name,
74+
"name": filename,
7575
"size": size,
7676
}
7777
return web.json_response(output)

0 commit comments

Comments
 (0)