File tree Expand file tree Collapse file tree 1 file changed +10
-4
lines changed
taskweaver/ext_role/image_reader Expand file tree Collapse file tree 1 file changed +10
-4
lines changed Original file line number Diff line number Diff line change @@ -23,10 +23,16 @@ def local_image_to_data_url(image_path):
2323 if mime_type is None :
2424 mime_type = "application/octet-stream" # Default MIME type if none is found
2525
26- # Read and encode the image file
27- with open (image_path , "rb" ) as image_file :
28- base64_encoded_data = base64 .b64encode (image_file .read ()).decode ("utf-8" )
29-
26+ try :
27+ # Read and encode the image file
28+ with open (image_path , "rb" ) as image_file :
29+ base64_encoded_data = base64 .b64encode (image_file .read ()).decode ("utf-8" )
30+ except FileNotFoundError :
31+ print (f"Error: The file { image_path } does not exist." )
32+ return None
33+ except IOError :
34+ print (f"Error: The file { image_path } could not be read." )
35+ return None
3036 # Construct the data URL
3137 return f"data:{ mime_type } ;base64,{ base64_encoded_data } "
3238
You can’t perform that action at this time.
0 commit comments