<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Building DocuPulse.AI]]></title><description><![CDATA[Real development lessons from building DocuPulse.AI with ASP.NET Core, covering PDF and document processing, file uploads, temporary cleanup, deployment, performance and production troubleshooting.]]></description><link>https://getdocupulse.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Fri, 04 Dec 2026 23:21:39 GMT</lastBuildDate><atom:link href="https://getdocupulse.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[How I Handle Temporary File Cleanup in an ASP.NET Core Document Processing App]]></title><description><![CDATA[How I manage temporary file cleanup, upload limits and stale files in an ASP.NET Core document processing app running in production.]]></description><link>https://getdocupulse.hashnode.dev/how-i-handle-temporary-file-cleanup-in-an-asp-net-core-document-processing-app</link><guid isPermaLink="true">https://getdocupulse.hashnode.dev/how-i-handle-temporary-file-cleanup-in-an-asp-net-core-document-processing-app</guid><category><![CDATA[Aspnetcore]]></category><category><![CDATA[dotnet]]></category><category><![CDATA[Web Development]]></category><category><![CDATA[programming]]></category><dc:creator><![CDATA[Rasel Sabrin]]></dc:creator><pubDate>Sun, 22 Nov 2026 10:21:26 GMT</pubDate><content:encoded><![CDATA[<p>Building a document-processing web application taught me something that is easy to overlook at the beginning: creating temporary files is simple, but managing their full lifecycle is not.</p>
<p>In <a href="https://getdocupulse.com/"><strong>DocuPulse.AI</strong></a>, users upload PDFs, images and other supported documents, process them, and download the generated result. Behind that simple workflow, the application may temporarily create input files, intermediate files and final output files.</p>
<p>Once the user has finished the task, those files no longer need to remain on the server.</p>
<p>That is where temporary file cleanup became an important part of the application rather than just a maintenance task.</p>
<h2>Why Temporary File Cleanup Matters</h2>
<p>When I first focused on individual document tools, the main questions were naturally about processing:</p>
<ul>
<li>Can the PDF be compressed correctly?</li>
<li>Can the pages be merged in the expected order?</li>
<li>Can an image be converted without breaking the output?</li>
<li>Can the generated file be downloaded successfully?</li>
</ul>
<p>But production introduced another question:</p>
<p><strong>What happens to all of those files after the user leaves?</strong></p>
<p>Leaving temporary files indefinitely would gradually consume storage and would not fit the privacy-focused processing model I wanted for <a href="http://DocuPulse.AI">DocuPulse.AI</a>.</p>
<p>I did not want the processing directories to become permanent storage.</p>
<p>My goal became straightforward:</p>
<ol>
<li>Accept the file needed for the task.</li>
<li>Validate it on the server.</li>
<li>Process it.</li>
<li>Keep the generated result available long enough for the user to download it.</li>
<li>Automatically remove temporary files after they are no longer needed.</li>
</ol>
<p>That final step needed to be part of the actual application design.</p>
<h2>Upload Limits Are Part of the Same Problem</h2>
<p>Cleanup starts with controlling what enters the processing environment.</p>
<p>For new file-processing tools in <a href="https://getdocupulse.com/">DocuPulse.AI</a>, I currently use a <strong>25 MB per-file upload limit by default</strong>, unless a specific tool has a practical reason to use a different limit.</p>
<p>The size limit is only one layer.</p>
<p>Server-side validation still matters because browser-side checks alone should not be responsible for deciding whether a file is safe or supported for a processing workflow.</p>
<p>I also try to generate safe output filenames rather than blindly reusing user-supplied names.</p>
<p>These decisions reduce unnecessary processing and keep temporary storage more predictable.</p>
<h2>I Initially Thought About Cleanup Per Tool</h2>
<p>As the project grew, one architectural question appeared:</p>
<p><strong>Should every document tool have its own cleanup service?</strong></p>
<p>At first that can sound reasonable.</p>
<p>A PDF compressor creates temporary files, so create a PDF compressor cleanup task.</p>
<p>An image tool creates files, so create another cleanup task.</p>
<p>A converter creates another output directory, so create another service.</p>
<p>The problem is that this approach can quickly create many background services that perform almost the same responsibility.</p>
<p>I actually started with a more tool-specific cleanup approach, including a <code>PdfCompressorTemporaryCleanupTask</code>.</p>
<p>While reviewing the project before production, I realized that I did not want to keep adding one cleanup service for every new tool unless the tool genuinely needed different cleanup behavior.</p>
<p>So I simplified the design.</p>
<h2>Moving Toward Shared Cleanup Responsibilities</h2>
<p>The current approach uses broader cleanup responsibilities instead of creating a nearly identical service for every tool.</p>
<p>Two important parts of that approach are:</p>
<p><code>MarkerBasedTemporaryCleanupTask</code></p>
<p>and</p>
<p><code>AppDataTemporaryCleanupTask</code></p>
<p>The names reflect the responsibilities I wanted to separate.</p>
<p>One cleanup path can work with temporary resources that are identified through the application's marker-based workflow, while another handles temporary content under the application's controlled <code>App_Data</code> processing area.</p>
<p>This gave me a better balance.</p>
<p>I can still keep tool-specific processing logic where it belongs, while avoiding a growing list of almost identical background cleanup services.</p>
<p>That was an important design lesson for me:</p>
<blockquote>
<p>Share infrastructure when the responsibility is genuinely shared, but do not force unrelated processing logic into a common abstraction.</p>
</blockquote>
<h2>Why I Use an Approximate 20-Minute Cleanup Window</h2>
<p>Deleting files immediately after processing sounds attractive, but it can create another problem.</p>
<p>The user may still need the generated file.</p>
<p>A download may not happen immediately. A user might inspect a result, switch tabs, or take a few minutes before downloading it.</p>
<p>So <a href="http://DocuPulse.AI">DocuPulse.AI</a> keeps temporary processing files only for a limited window rather than treating them as permanent storage.</p>
<p>In the current production workflow, temporary uploaded and generated files are designed to be automatically removed within approximately <strong>20 minutes after the related processing or session activity</strong>.</p>
<p>The exact idea is more important than the number itself:</p>
<p><strong>temporary files should live long enough to complete the real user workflow, but not remain indefinitely.</strong></p>
<p>For my current project, that balance works well for the type of short-lived PDF, image and document processing tasks the site performs.</p>
<h2>Cleanup Must Not Break an Active Job</h2>
<p>Automatic deletion introduces its own risk.</p>
<p>A cleanup task that is too aggressive can be worse than having no cleanup task at all.</p>
<p>For example, I do not want a background process to decide that a file is old and delete it while a conversion or download workflow still depends on it.</p>
<p>That is why I think about cleanup eligibility rather than simply asking:</p>
<p><strong>Does this file exist?</strong></p>
<p>The more useful questions are:</p>
<ul>
<li>Is the file part of a controlled temporary location?</li>
<li>Is it old enough to be considered stale?</li>
<li>Does the application have enough information to treat it as temporary?</li>
<li>Could an active processing operation still be using it?</li>
<li>Is deletion failure handled safely?</li>
</ul>
<p>This is also one reason I prefer controlled application directories and marker-based information over scanning arbitrary locations.</p>
<h2>Failed Jobs Matter Too</h2>
<p>Successful processing is the easy case.</p>
<p>The more interesting cleanup problems appear when something fails halfway through.</p>
<p>Imagine a workflow that:</p>
<ol>
<li>receives an upload,</li>
<li>writes a temporary input,</li>
<li>starts processing,</li>
<li>creates an intermediate file,</li>
<li>then fails before generating the final download.</li>
</ol>
<p>If cleanup logic only runs after a successful result, those partial files can remain behind.</p>
<p>Over time, small failures can create a large stale-file problem.</p>
<p>I therefore treat scheduled/background cleanup as a second line of defense even when individual processing workflows already try to clean up after themselves.</p>
<p>Immediate cleanup handles the normal path.</p>
<p>Background cleanup catches what the normal path may miss.</p>
<h2>Production Testing Was More Important Than the Code</h2>
<p>One of the biggest lessons from this work was that writing a cleanup service does not prove cleanup actually happens.</p>
<p>I tested the workflow locally first, but I also wanted to see what happened in the real hosted environment.</p>
<p>Before finalizing the production deployment, I tested active document tools and then waited to see whether temporary processing data disappeared as expected.</p>
<p>PDF Compressor was particularly useful for this verification because it gave me a straightforward real workflow:</p>
<ul>
<li>upload a PDF,</li>
<li>process it,</li>
<li>download the result,</li>
<li>confirm the tool still works normally,</li>
<li>then check the relevant temporary location after the cleanup period.</li>
</ul>
<p>That verification mattered more to me than simply confirming that the project compiled.</p>
<p>A background task can look perfectly correct in source code and still fail in production because of application lifecycle behavior, directory permissions, hosting differences or deployment configuration.</p>
<h2>Hosting Changes the Problem</h2>
<p>Local development gives me a lot of control.</p>
<p>Production hosting does not always behave exactly the same way.</p>
<p>For cleanup tasks, I have to consider questions such as:</p>
<ul>
<li>Is the application actually running when the cleanup task is expected to execute?</li>
<li>Does the application pool recycle?</li>
<li>Are the target folders writable and deletable?</li>
<li>Are paths the same after deployment?</li>
<li>Could a deployment leave older temporary data behind?</li>
<li>What happens after an application restart?</li>
</ul>
<p>These are operational questions, not just C# questions.</p>
<p>That changed the way I evaluate background services.</p>
<p>Now I do not consider a cleanup workflow complete until I have observed its behavior in the deployment environment.</p>
<h2>Why I Did Not Create a Cleanup Service for Every Tool</h2>
<p>This was probably the most useful architectural decision from the cleanup work.</p>
<p><a href="http://DocuPulse.AI">DocuPulse.AI</a> contains multiple PDF, image and document workflows, and I expect more tools to be added over time.</p>
<p>Creating another hosted cleanup service every time I add a tool would increase complexity quickly.</p>
<p>Instead, I prefer a small number of clearly defined cleanup mechanisms that can safely cover shared temporary-processing locations.</p>
<p>I will still create specialized cleanup behavior if a future tool genuinely needs it.</p>
<p>But the default is no longer:</p>
<p><strong>new tool = new cleanup service.</strong></p>
<p>The question is:</p>
<p><strong>Does this tool introduce a cleanup requirement that the existing infrastructure cannot safely handle?</strong></p>
<p>If the answer is no, I keep the existing infrastructure.</p>
<h2>Simple Architecture Helps During Production Incidents</h2>
<p>There is another benefit to keeping cleanup centralized and understandable.</p>
<p>When something goes wrong in production, I need to know where to look.</p>
<p>If twenty tools have twenty almost-identical scheduled services, diagnosing a stale-file problem becomes harder.</p>
<p>With fewer cleanup responsibilities, I can inspect:</p>
<ul>
<li>the temporary directories,</li>
<li>marker behavior,</li>
<li>file age,</li>
<li>task execution,</li>
<li>application logs,</li>
<li>hosting lifecycle,</li>
<li>and the specific processing workflow.</li>
</ul>
<p>That makes troubleshooting more practical.</p>
<p>For a project I actively maintain, operational simplicity matters.</p>
<h2>What I Learned</h2>
<p>A few lessons from this implementation stand out.</p>
<h3>Temporary files need an explicit lifecycle</h3>
<p>Creating a file should always lead to the question: <strong>when will this file be removed?</strong></p>
<h3>Validation and cleanup are connected</h3>
<p>Controlling size, type, filenames and processing locations makes later cleanup safer and more predictable.</p>
<h3>Immediate cleanup is not enough</h3>
<p>Processing can fail. Applications can restart. Unexpected paths happen.</p>
<p>A background cleanup mechanism provides a useful safety net for stale temporary data.</p>
<h3>Do not duplicate infrastructure without a reason</h3>
<p>A new document tool does not automatically require a new cleanup service.</p>
<h3>Production behavior is the real test</h3>
<p>A successful build tells me the code compiles.</p>
<p>A successful production test tells me the workflow actually works where users depend on it.</p>
<h2>The Approach I Use Today</h2>
<p>My current approach in <a href="https://getdocupulse.com/">DocuPulse.AI</a> is intentionally practical:</p>
<ul>
<li>validate uploads on the server,</li>
<li>use controlled temporary processing locations,</li>
<li>use a <strong>25 MB per-file default limit</strong> for new file-processing tools unless the workflow requires otherwise,</li>
<li>generate safe filenames,</li>
<li>clean up normally during processing where appropriate,</li>
<li>use broader background cleanup tasks for stale temporary data,</li>
<li>keep temporary uploaded and generated files for only a limited period,</li>
<li>and verify cleanup behavior after production deployment.</li>
</ul>
<p>The system will continue to evolve as the project grows, but I want that evolution to be driven by real requirements rather than adding services simply because another tool was added.</p>
<h2>Building This in a Real Project</h2>
<p>This cleanup approach comes from my ongoing work on <a href="https://getdocupulse.com/"><strong>DocuPulse.AI</strong></a>, where I build and test practical PDF, image and document processing workflows in production.</p>
<p>If you want to see the project behind these lessons, you can explore <a href="https://getdocupulse.com/"><strong>DocuPulse.AI – Free Online PDF, Image &amp; Document Tools</strong></a>.</p>
<p>I am continuing to document the practical lessons that come from building, deploying and maintaining the project rather than only writing about the finished features.</p>
<p>If you have worked on temporary file cleanup in an <a href="http://ASP.NET">ASP.NET</a> Core application, I would be interested to hear how you handle active files, stale jobs and cleanup timing in production.</p>
]]></content:encoded></item></channel></rss>