Download large sized files using HTTP request

Hi Experts

I have created an automation that downloads multiple files using a HTTP Request. However when moving the automation into production I have found that there is a problem with large sized files (+1GB) as the job fails with exit code 0xE0434352.

I have reached out to UiPath and they have replied that it is a known error which will be fixed in WebAPI version 1.20.0 but currently the release date is unknown.

As a workaround my thought is to use an Invoke Code with the following C# code:

// Initialize web client
using (System.Net.WebClient client = new System.Net.WebClient()) {
		
	// Add bearer token to header
	client.Headers.Add("Authorization", "Bearer " + in_AccessToken);
		
	// Download the file
	client.DownloadFile(in_RequestUrl, in_FileName);
		
}

I am not an expert in C# - will this code be sufficient? And how about error handling? Should I put the Invoke Code activity into a Try Catch activity or is it better to have the Try Catch exception handling within the code?


Taken from: HttpUtility.HtmlDecode Method (System.Web) | Microsoft Learn

So, we would recommend to set it up with the mentioned HttpClient

Thanks @ppr

Unfortunately it seems that using the System.Net.Http.HttpClient is also not able to handle the large files. The file downloads when using the System.Net.WebClient.

At present, we would neither agree nor disagree with the statement.

  • what was done in detail?
  • what is failing?

I have re-written the code to:

// Try downloading file
try {
	
	using (System.Net.Http.HttpClient client = new System.Net.Http.HttpClient()) {
		
		// Add bearer token token to request header
		client.DefaultRequestHeaders.Add("Authorization", "Bearer " + in_AccessToken);
		
		// Send the HTTP GET request
		System.Net.Http.HttpResponseMessage response = client.GetAsync(in_RequestUrl).Result;
		
		// Check if response was successful
		if (response.IsSuccessStatusCode) {
			
			// Get the response content
			byte[] content = response.Content.ReadAsByteArrayAsync().Result;
			
			// Save the content to a file
			System.IO.File.WriteAllBytes(in_FileName, content);
			
		}
		
		// Throw an exception if the response was not successful
		else {
			
			throw new Exception(string.Format("{0} (Status code: {1})", response.RequestMessage, response.StatusCode));
			
		}
		
	}
	

}

// Catch any exception and rethrow
catch (Exception ex) {
	
	throw new Exception("Download of file failed: " + ex.Message);
	
}

It runs for a while and then it stops with the exception message:
One or more errors occurred. (A task was canceled.)

This is similar to the behavior of UiPath’s HTTP Request activity.

Instead of using client.GetAsync(in_RequestUrl).Result I have tried with await client.GetAsync(in_RequestUrl). But then the compiler returns an error saying:

The ‘await’ operator can only be used within an async method. Consider marking this method with the ‘async’ modifier and changing its return type to ‘Task’

Not sure how I can implement that in an Invoke Code activity nor if it will fix the problem.

There are several additional method and options. Maybe you can check here

I cannot seem to find a way on how to implement the async Task in an Invoke Code activity.

But thanks anyway.