Misc

Files From a URL - Downloading Without a Click

A URL Is a Filename

Every other download path in GPAL starts with an element and a click. This one does not. WithFileName recognizes an http or https address, fetches it to a local file before the chain continues, and carries on with that local path, so the converter, the grid reader, and everything else see an ordinary file. The fetch happens in the call where you wrote it, not somewhere later, so a failure is reported where you can see it. SourceUrl remembers where the file came from, which is how a workflow later tells a downloaded file from one that was always on disk.

// Fetched on this line, parsed on the next

GPALFile versions = (GPALFile)GPAL.File

.WithFileName("https://googlechromelabs.github.io/chrome-for-testing/known-good-versions.json");


GPAL.Converter.WithInput(versions).SaveTo(ref grid);


// Where it came from, and where it landed

GPAL.PublishSimpleEvent(GPALEventType.NOTICE, $"[{versions.SourceUrl}]"); // the url

GPAL.PublishSimpleEvent(GPALEventType.NOTICE, $"[{versions.Filename}]"); // the local file the rest of the workflow uses

NOTE

The download lands in the GPAL temp directory under the name the url ends in, or "download" when the url has no name in it. Everything after WithFileName works on that local copy, so the url is read exactly once no matter how many times the file is used.

When the File Is Behind a Session

Plenty of files are not simply public. The url only works for someone who is signed in, or who has the cookie a challenge page handed out, or whose connection looks like the browser the site expects. WithBrowser, set before WithFileName, says this file is behind something an ordinary connection cannot get past. The request then goes out from inside the page, carrying the session the browser already earned: its cookies, its TLS fingerprint, its header order, and any anti-bot clearance it holds. If the page cannot hand the bytes over, GPAL falls back to downloading it in a new tab and cleans the tab up afterwards. Without a browser there is only GPAL's own connection, which is all a public file needs.

// Sign in once, then pull files that only a signed-in session can see

IBrowser browser = GPAL.Browser

.WithBrowserType(BrowserType.Chrome)

.WithAutomationEngine(AutomationEngine.PuppeteerPort)

.ToGPALObject();


browser.GoTo("https://portal.example.com/login");

// ... whatever signing in takes


GPALFile statement = (GPALFile)GPAL.File

.WithBrowser(browser) // before the filename, not after

.WithFileName("https://portal.example.com/statements/2026-08.pdf");


statement.CopyTo(@"C:Statementsaugust.pdf");

NOTE

WithFileName does the work, so the browser has to be attached before it. WithBrowser after WithFileName is too late: the fetch has already happened on GPAL's own connection.

Which Path a Download Takes

GPAL now has two different ways to end up with a file, and they suit different problems. A click download is right when the file only exists as the result of pressing something: an export button, a generated report, a link whose href is built by script. A url download is right when you already know the address, which is most of the time once a workflow has read a page. The url path is the quieter of the two. There is no dialog to handle, no watching a directory for a file to appear, and no timing to get wrong, because the call does not return until the bytes are there.

WARNING

Going through the browser means the page has to be open and the session has to be live. For a public file it is slower and buys nothing. Attach a browser when the url needs the session, and leave it off when it does not.

💬 Ask GPAL