Catch download errors from attachments.download()

416
1
01-20-2021 06:13 PM
IanHamilton2
New Contributor III

Hi, I have stumbled upon what seems to be a spurious error when downloading attachments. One of my jpg attachments downloaded but was corrupt - bottom half of image is grey. The original is not corrupt. I then try to process this corrupt image and my script breaks. Is there a way of 'catching' the result. I know attachments.download()  should return a file path but as the image did save to file I expect this would not return an error. I haven't been able to replicate the error as all the attachments subsequently download correctly. It does seem to have been a slow connection or file system type error. Is there a good way to check if an image file is corrupt. I fails when I try to rotate the image. I would like to re-download the suspect image immediately if I can detect the condition.

0 Kudos
1 Reply
VictorTey
Esri Contributor

Hi, I have a couple of suggestions,

1. check size of image file (may not be 100%)

2. use PIL (python imaging library) to  open() and verify() the image file.