Data Scraping of an Image, what to assign its variable as?

Hi all,

Currently, I have a datascrape activity that also datascrapes an image.
image
The above image is how I perform the assign feature. Currently the variable type for my ‘bakerImg’ is UiPath.Core.Image, but there is an error. What should I assign the variable type as?

My goal for this is to display the image in an email afterwards. Hopefully I can get some clarifications.

Regards

Hi @SRoyi

Could you screenshot the error and paste here for better understanding.

Hi,

Here is the error message:
image

Try like this @SRoyi

CType(row2("Baker Image"), UiPath.Core.Image)

Hope it helps!!

Hi there,

The assign works, thanks

However I have another question:
image
How can I implement the image variable together with my email body?

Regards

Hi @SRoyi

Try the below expression:

"Dear " + custName.ToString + "," + Environment.NewLine + Environment.NewLine +
"Your favourite baker, " + favBaker.ToString + ", has been featured in today's Featured Homebakers." + Environment.NewLine +
"To celebrate, we are offering an exclusive 15% discount on " + favBaker.ToString + "'s treats using the code 'FEATURED15' at checkout." + Environment.NewLine +
"Explore his delightful creations on our website and enjoy this limited-time offer as a valued customer." + Environment.NewLine +
"Thank you for your support." + Environment.NewLine +
Convert.ToBase64String(bakerImg) + Environment.NewLine + Environment.NewLine +
"Warm regards," + Environment.NewLine +
"<b>BakerBuzz</b>"

Check and tell whether it’s working for you
Hope it helps!!

Hi there,

I have tried your method and got this error instead:
image

It seems to not be the right way

@SRoyi

Try this once:

"Dear " + custName.ToString + "," + Environment.NewLine + Environment.NewLine +
"Your favourite baker, " + favBaker.ToString + ", has been featured in today's Featured Homebakers." + Environment.NewLine +
"To celebrate, we are offering an exclusive 15% discount on " + favBaker.ToString + "'s treats using the code 'FEATURED15' at checkout." + Environment.NewLine +
"Explore his delightful creations on our website and enjoy this limited-time offer as a valued customer." + Environment.NewLine +
"Thank you for your support." + Environment.NewLine +
Convert.ToBase64String(bakerImg.ToByteArray) + Environment.NewLine + Environment.NewLine +
"Warm regards," + Environment.NewLine +
"<b>BakerBuzz</b>"

Hope it helps!!

Hi, thanks for your suggestion but I am still experiencing an error, stating “‘ToByteArray’ is not a member of UiPath.Core.Image’”

Hi @SRoyi

Try the below syntax once:

"Dear " + custName.ToString + "," + Environment.NewLine + Environment.NewLine +
"Your favourite baker, " + favBaker.ToString + ", has been featured in today's Featured Homebakers." + Environment.NewLine +
"To celebrate, we are offering an exclusive 15% discount on " + favBaker.ToString + "'s treats using the code 'FEATURED15' at checkout." + Environment.NewLine +
"Explore his delightful creations on our website and enjoy this limited-time offer as a valued customer." + Environment.NewLine +
"Thank you for your support." + Environment.NewLine +
Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(bakerImg.ToString)) + Environment.NewLine + Environment.NewLine +
"Warm regards," + Environment.NewLine +
"<b>BakerBuzz</b>"

Hope it helps!!

@SRoyi

Why not use create html content activity?

Cheers

1 Like

Is it working for you @SRoyi

If yes make my post mark as solution to close the loop, else post your questions I am happy to help!!

Happy Automation!!

@SRoyi -

Try this below for converting your object to UiPath.core.image.

' Assuming you have an object named 'obj' that you want to convert to UiPath.Core.Image

Dim obj As Object = '...'

' Check if the object can be cast to UiPath.Core.Image
If TypeOf obj Is UiPath.Core.Image Then
    ' If the object is already UiPath.Core.Image, simply cast it
    Dim image As UiPath.Core.Image = DirectCast(obj, UiPath.Core.Image)
    ' Now you can use 'image' variable as UiPath.Core.Image type
Else
    ' Handle the case where the object cannot be directly cast to UiPath.Core.Image
    ' This might involve converting the object to an image format or handling the error appropriately
    ' For example, if 'obj' is a file path, you might need to load the image from the file
    ' Alternatively, you might throw an exception or log an error message
End If

Hi, I have implemented your solution, and I have been doing some testing and the above solution you provided works, but right now it cannot assign the image to the variable ‘bakerImg’
image

With the error:
image

It was the conversion issue, @SRoyi

Could you try the below one,

DirectCast(row2("Baker Image"), UiPath.Core.Image)

I have tried and still doesnt work. The error message is the same
image

For reference, bakerImg’s variable type is UiPath.Core.Image

If it cant be fix then its fine, I will do another function, or potentially scrap the idea of using image in a email

what is the data contains in the row2(“Baker Image”)… @SRoyi

If the data is path then use the below one,

New UiPath.Core.Image(row2("Baker Image").toString)

Hope you understand!!

The data in row2(“Baker Image”) is this:
image

I use data scrape to retrieve the images on a web page.

Okay then @SRoyi

Use the below one,

New UiPath.Core.Image(row2("Baker Image").toString)

It will work!!

since which Package version is the Constructor available for an URL. Can you please elaborate more along with working samples and documentation screenshots?. Thanks for your support.