Search code examples
c#asp.net.netamazon-s3ironpdf

HTML to PDF using ironPDF getting error "System.Exception: IronPDF requires a safe directory to unpack resource files." in C#


I'm working on an application that runs on a virtual machine. Among other things, the application runs tasks, and one of them is responsible for generating PDFs and saving them directly to S3.

In the production environment, it works smoothly, but in the test environment, the PDFs are not being generated, and from the logs, I have this error (there are no differences in the code between production and test where the PDF is generated):

IronPDF requires a safe directory to unpack resource files. Please set IronPdf.Installation.TempFolderPath before using IronPDF E.g. IronPdf.Installation.TempFolderPath ="C:\Safe\Path\"; Documentation:https://ironpdf.com/c%23-pdf-documentation/html/F_IronPdf_Installation_TempFolderPath.htm Please read the installation FAQ: https://ironpdf.com/docs/questions/installation/

The error is telling me to set up a safe folder... but how do I set it? Do I need to write a logic to periodically empty it?

I'm not sure where to start, and in the code, I don't see any IronPDF configurations other than the license key.


Solution

  • This is from the Iron Software team.

    Based on the exception message, it indicates that you need to set a temporary folder with write access for the library. This is mandatory for AWS Lambda. In some scenarios on Azure Functions, it may still work without setting the temporary folder. Please use the code below:

    // AWS temporary storage
    var awsTmpPath = @"/tmp/";
    
    //set IronPDF Temp Path
    IronPdf.Installation.TempFolderPath = awsTmpPath;
    IronPdf.Installation.CustomDeploymentDirectory = awsTmpPath;
    

    If this does not resolve the issue, please contact Iron Software support (support@ironsoftware.com) with the following details:

    • IronPdf version
    • Project type (ASP.NET, ASP.NET MVC, etc.)
    • Deployment type (Azure Web App, Azure Function, AWS)
    • Deployment configurations
    • Log files

    To enable logging, use the code below:

    // Place at the top of your code, prior to running any other IronPdf methods
    IronPdf.Logging.Logger.EnableDebugging = true;
    IronPdf.Logging.Logger.LogFilePath = "Default.log";
    IronPdf.Logging.Logger.LoggingMode = IronPdf.Logging.Logger.LoggingModes.All;