async def _download_file_stream(
        self,
        entity: FileEntity,
        stream: AsyncIterator[bytes],
        temp_path: str,
        max_size: int,
    ) -> int:
        """Download file stream to temporary path."""
        downloaded_size = 0
        # Truncate long URLs for logging
        url_display = (
            entity.download_url[:100] + "..."
            if len(entity.download_url) > 100
            else entity.download_url
        )
        logger.info(
            f"Downloading file from source (entity_id: {entity.entity_id}, "
            f"name: {entity.name}, url: {url_display})"
        )

        async with aiofiles.open(temp_path, "wb") as f:
            async for chunk in stream:
                downloaded_size += len(chunk)

                # Safety check to skip files exceeding max size
                if downloaded_size > max_size:
                    await self._handle_oversized_file(
                        entity, f, temp_path, max_size, downloaded_size
                    )
                    return downloaded_size

                await f.write(chunk)

                # Log progress for large files
                if entity.total_size and entity.total_size > 10 * 1024 * 1024:  # 10MB
                    progress = (downloaded_size / entity.total_size) * 100
                    logger.info(
                        f"Download progress for {entity.name}: {progress:.1f}% "
                        f"({downloaded_size}/{entity.total_size} bytes)"
                    )

        return downloaded_size
Download file stream to temporary path.
backend/airweave/platform/file_handling/file_manager.py