Read excel error after save attachments

Dears,

  When I use "Save Attachemnts" to download a Excel file and read it immediately, I found when the file is large more than 6MB and the file is not download fully and when read it said need to be repaired. 
  This time I and "Path Exists" to judge the downloaded file whether exists but always return "True". 
  So I don't know how to handle with it, may I get your kindly help, thanks!

Hi @Taylor_He ,

Welcome to community forum.

Try using Wait for Download Activity and check if that works for you.

Hi @Taylor_He

Use Wait for Download activity.

Check the below docs for information:

Check the below thread

Regards

Hi,

Try with wait for download activity. Bot will wait till complete download the file. Provide timeout ms 600000

Hey @Taylor_He ,

Try this, There is an activity in your activities panel - Wait for Download

image

Thanks for your help! But when I used “Wait for Download” still got the same error.

I sent two mails with Excel attachement, one size is 8M and another is 6M,the Excel file is fill with too many formulars. I invoked the “Wait for Download” and put the “Save Attachments” inside it. The result is 8M file download correctly but the 6M file is wrong. So confused!

You mean to tell, you are getting corrupted file?

Yes. The file was not fully downloaded, and when I added a 10-second delay before opening the file, everything worked fine.

When dealing with large files in UiPath, especially when downloading attachments from emails, you may encounter issues with file completeness if you try to read the file immediately after downloading. It’s important to allow sufficient time for the file to be fully downloaded before attempting to read or manipulate it.
Here are some recommendations to handle this situation:

  1. Use a Delay Activity: Insert a “Delay” activity after the “Save Attachments” activity to introduce a pause, allowing time for the file to be completely downloaded.
  2. Check File Size: Use the “Get Files” or “Directory.GetFiles” activity along with a condition to check the size of the file before attempting to read it. You can specify a minimum file size threshold to ensure the file is large enough to be considered fully downloaded.

Thank you very much!
I tested this idea by getting the ContentStream.Length of the attachment before saving, and then compare the size of the download file, when I suddenly realized that the two values were the same every time, but strangely the ContentStream.Length of the attachment was different every time.

Instead of using ContentStream, can you try with FileInfo, like
Dim maxAttempts As Integer = 3
Dim currentAttempt As Integer = 0
Dim filePath As String = “Path\to\your\downloaded\file.xlsx”
Dim minFileSize As Long = 6 * 1024 * 1024 ’ 6MB in bytes

While currentAttempt < maxAttempts AndAlso New FileInfo(filePath).Length < minFileSize
LogMessage("File size is below the threshold. Waiting for download to complete. Attempt: " & (currentAttempt + 1).ToString())
Delay(TimeSpan.FromMinutes(1)) ’ Adjust the delay duration as needed
currentAttempt += 1
End While

If currentAttempt < maxAttempts Then
’ File is large enough, proceed with reading or processing
Else
’ Max attempts reached, handle the situation accordingly
LogMessage(“Downloaded file did not reach the desired size within the specified attempts.”)

I’m sorry, I may not have described it clearly.
First of all, the Attachment size of the mail is not fixed, some are 10KB, 100KB or even 10 or more MB. Previously, there was no problem with Save Attachment only. Suddenly, I found that there was a problem with opening an attachment of about 6MB immediately after downloading, but there was no problem with manual downloading. At this time, it was found that the file size was only a few hundred KB and was not fully downloaded.
Then I try to get the size of the email attachment first, using the ContentStream.Length method, and then get the FileInfo.length of the file in the downloaded destination folder, and then compare the two values to see if they are equal, and delay for 1S if they are not equal.The strange thing is that the size of the attachment is different every time, and the values of the two are equal every time, so it is still not complete with the previous download, and this logic is not effective at all.

I mean to say you can check the file size Before and after the download. For this comparison you can use FileInfo(Your_filePath).Length function