How to load image in dashboard from ignition image browser in preview mode

This is the scripting i have done for upload image buttton in Scada and also selected the image component named imgStudent. The image path is displaying in preview mode but the image that i am selecting is not get displayed in dashboard. I've given the attribute. Selected in 2nd last line of code but it's not working so which attribute should i give to display the image.

# Import the system module
import system
# Open the file dialog to select an image from the PC documents directory

filePath = system.file.openFile()

fileFilter="Image Files (*.png;*.jpg;*.jpeg) |*.png;*.jpg;*.jpeg; *)"

event.source.parent.getComponent('Mypath').text = filePath

#event.source.parent.getComponent('ImgStudent').source = filePath

imageBytes = system.file.readFileAsBytes(filePath)

imageComponent = event.source.parent.getComponent('ImgStudent').Selected
imageComponent = imageBytes

First of all, there is no need to do this:

I don't believe any of this is needed:

This code is just assigning the Selected property of the image component [which I'm not sure exists] to the variable imageComponent, and then immediately overwriting it with imageBytes.

Since this appears to be a file off of your local computer, I believe this is the code you need:

# Get the filepath for the image from the PC
filePath = system.file.openFile()

# Display the file path in a label by assigning it to the label's text property
event.source.parent.getComponent('Mypath').text = filePath

# Designate the file path as a file,
# and display the image in the image component 
# by assigning the designated file path to the image component's path property
event.source.parent.getComponent('ImgStudent').path = 'file:///' + filePath

I tried your code but still error is occurring.

Traceback (most recent call last):
  File "<event:actionPerformed>", line 8, in <module>
AttributeError: 'NoneType' object has no attribute 'path'

Ignition v8.1.28 (b2023060110)
Java: Azul Systems, Inc. 11.0.18

This must be wrong:

Inside the script editor, highlight this part of the code:

Then, with it highlighted, click this button:

Finally, select the 'Image Path' property of your image component:

This should correct your code.

The code is working now.