Skip to content

Commit

Permalink
Fix downloading full content of the file. (#559)
Browse files Browse the repository at this point in the history
* Fix downloading full content of the file.

* Fix review.

* tweaks.
  • Loading branch information
mariacarmina authored Jul 24, 2024
1 parent 83b5ef0 commit 542a860
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/components/core/handler/downloadHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export async function handleDownloadUrlCommand(
}
}
}
const fileMetadata = await storage.fetchSpecificFileMetadata(task.fileObject, true)
const inputStream = await storage.getReadableStream()
const headers: any = {}
for (const [key, value] of Object.entries(inputStream.headers)) {
Expand All @@ -85,8 +86,13 @@ export async function handleDownloadUrlCommand(
const objTemp = JSON.parse(JSON.stringify(headers)?.toLowerCase())
if (!('Content-Length'?.toLowerCase() in objTemp))
headers['Transfer-Encoding'] = 'chunked'
// ensure that the right content length is set in the headers
headers['Content-Length'.toLowerCase()] = fileMetadata.contentLength

if (!('Content-Disposition'?.toLowerCase() in objTemp))
headers['Content-Disposition'] = 'attachment;filename=unknownfile' // TO DO: use did+serviceId+fileIndex
headers[
'Content-Disposition'.toLowerCase()
] = `attachment;filename=${fileMetadata.name}`
if (encryptFile) {
// we parse the string into the object again
const encryptedObject = ethCrypto.cipher.parse(task.aes_encrypted_key)
Expand Down

0 comments on commit 542a860

Please sign in to comment.