# XXX Check if this is actually downloadable
- headers = {
- "Content-Type" : file.mimetype or "application/octet-stream",
- "Content-Disposition" : "attachment; filename=%s" % file.basename,
-
- # XXX StreamingResponse does not allow us to set a Content-Length header
- # because starlette is getting very confused about how much data is to be
- # sent or has been sent already.
- #"Content-Length" : "%s" % file.size,
-
- # This content should not be indexed
- "X-Robots-Tag" : "noindex",
- }
-
- return fastapi.responses.StreamingResponse(file.stream(), headers=headers)
+ return fastapi.responses.StreamingResponse(file.stream(), headers=file.headers)
# Add everything to the APIv1
yield chunk
- async def sendfile(self, dst, chunk_size=65536):
- """
- Sends the payload of the file into the given file descriptor
- """
- src = await self.open()
-
- return await asyncio.to_thread(self._sendfile, src, dst, chunk_size=chunk_size)
-
- def _sendfile(self, src, dst, chunk_size=65536):
- while True:
- chunk = src.read(chunk_size)
- if not chunk:
- break
-
- dst.write(chunk)
-
@property
- async def payload(self):
- """
- Returns the entire payload at once
- """
- # Open the file
- f = await self.open()
-
- # Read everything in a separate thread
- return await asyncio.to_thread(f.readall)
+ def headers(self):
+ return {
+ "Content-Type" : self.mimetype or "application/octet-stream",
+ "Content-Disposition" : "attachment; filename=%s" % self.basename,
+
+ # XXX StreamingResponse does not allow us to set a Content-Length header
+ # because starlette is getting very confused about how much data is to be
+ # sent or has been sent already.
+ #"Content-Length" : "%s" % self.size,
+
+ # This content should not be indexed
+ "X-Robots-Tag" : "noindex",
+ }
def buildid_to_path(buildid):