I am attempting to download a file from a very old website that requires me to be signed in, in order to download. When I use the Download from url activity, I get the html of the login page, not the actual pdf I’m trying to retrieve. This suggests I don’t have the session cookie from the Use Browser context and I’m unauthenticated. I can retrieve the cookies with an Inject JavaScript but of course I only get the non-HttpOnly cookies, no session cookie. There is no formal API, so I can’t simply GET it with an authenticated call, though if I manually grab the cookies from my browser and paste them into Postman, the download does work, again suggesting I need the correct session data in UiPath. Any ideas how I can retrieve the file?
Hey @ben.smith
That sounds like a tricky one, and to be honest - this is the kind of case where you really need to test it live to understand what’s going on behind. That said, I’d suggest keeping things simple and using the browser interface instead of trying to replicate the session with HTTP requests.
If the file can be downloaded by clicking a button or link after logging in, you can automate that directly using Use Browser and simulate the user action. This way, you don’t need to worry about session cookies, headers etc. - the browser already holds the full authenticated session.
Makes sense
My intent is to immediately upload the file to another API. Ideally I’d just read the byte array of the file as a stream, convert it to a base64 string, and POST it to the new API - no muss, no fuss. I really don’t need a copy of it stored anywhere or anything.
@ben.smith
Makes total sense - thanks for clarifying! ![]()
The challenge is that UiPath’s browser automation doesn’t give you direct access to the file stream from a click-based download. Once a file is triggered for download via UI interaction, it’s saved locally by the browser, and UiPath can only work with it from the file system.
So, in this case, one way to go would be:
- Let the browser download the file using the authenticated session.
- Use Wait for Download to capture the downloaded file path.
- Read the file into a byte array using
fileBytes = System.IO.File.ReadAllBytes("C:\path\to\file.pdf") - Convert to Base64 using
Convert.ToBase64String(fileBytes)and POST it to your target API.
Cool. That could work I suppose. Does the Wait for Download activity give me the destination download path? And do I need to clean it up (delete from the folder) after I retrieve and convert it?
@ben.smith
Yes, exactly - the Wait for Download activity gives you the full file path as soon as the browser finishes saving it. You can use that path right away to read the file into a byte array and process it further.
As for cleanup - yes, you can delete the file after you’ve converted it. You can either use the Delete activity to remove the file after you’re done with it.
Let me know how it goes and if this approach works for you ![]()
Can I use Go To URL and then Wait for Download if I already have the link extracted from a table, rather than Click?
@ben.smith
Yes, you can use Go To URL followed by Wait for Download if you already have the direct download link. As long as the browser session is authenticated and the file gets downloaded automatically when you navigate to that URL, the Wait for Download activity will still capture it properly. Just make sure you trigger the download in the same Use Browser scope where the session is active.
Hey @ben.smith - glad to hear it worked! ![]()
If the solution helped, feel free to mark one of my posts as the solution so others can find it easily in the future.
Thanks again and good luck with your project!
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.