How to set the file target for a high res screenshot

This Post has greatly helped me. A few Years have gone by, its 2024, and Unreal 5.4 just came out. Here is some updated code for my fellow dev looking to make this work.

#include "Engine.h"
#include "HighResScreenshot.h"
#include "ImageUtils.h"
#include "Misc/FileHelper.h"
#include "Containers/ArrayView.h"

void AGimbal_Core::takeGimbalHighResCapture(FString filePath)
 {
	GIsHighResScreenshot = true;
	GetHighResScreenshotConfig().ResolutionMultiplier = 2;
	//Configure High Res Screenshot. Include params if desired...
	UGameViewportClient* ViewportClient = GetWorld()->GetGameViewport();
	//Prevents the overwrite of previously taken HighResScreenshots.
	ViewportClient->OnScreenshotCaptured().Clear();

	//Cant use filePath as a function parameter, therefore need to 'capture' it (Captureing an object by name makes a lambda-local copy of the object.)
	ViewportClient->OnScreenshotCaptured().AddLambda([filePath](int32 SizeX, int32 SizeY, const TArray<FColor>& Bitmap)
 {
		//Make sure that all alpha values are opaque.
		TArray<FColor>& RefBitmap = const_cast<TArray<FColor>&>(Bitmap);
		for (auto& Color : RefBitmap)
			Color.A = 255;

		TArray64<uint8> compressedBitmap;
		FImageUtils::PNGCompressImageArray(SizeX, SizeY, RefBitmap, compressedBitmap);
		FFileHelper::SaveArrayToFile(TArrayView<const uint8>(compressedBitmap), *filePath, &IFileManager::Get(), static_cast<uint32>(0)); 
                });

	GAreScreenMessagesEnabled = true;
	GetWorld()->GetGameViewport()->Viewport->TakeHighResScreenShot();
}