CardHeader ImageUrl

Is there a way to supply the base 64 byte data instead of the url for the image?

Something like <CardHeader ImageSrc="data:image;base64, ......">

The reason for this is that I have my image stored in a database and not in a file.

Thanks,
Frank

11 Replies 1 reply marked as answer

BS Balasubramanian Sattanathan Syncfusion Team December 15, 2020 12:45 PM UTC

Hi Frank, 

Greetings from Syncfusion Support. 

We have validated your requirement at our end and let you know that we can achieve by making use of the below code snippet. And also we let you know that the property ImageSrc has been deprecated at our end and we can use it as ImageUrl.  

<SfCard ID="SecondCard"> 
    <CardHeader Title="Harrisburg Keith" SubTitle="@CardSubTitle" ImageUrl=@CardImage /> 
    <CardContent Content="Hi, I'm creative graphic design for print, new media based in Edenbridge" /> 
    <CardFooter> 
        <CardFooterContent> 
            <table> 
                <tr> 
                    <td> <div class="e-icons ChatIcon"></div></td> 
                    <td> <div class="e-icons StarIcon"></div></td> 
                    <td> <div class="e-icons AlarmIcon"></div></td> 
                </tr> 
            </table> 
        </CardFooterContent> 
    </CardFooter> 
</SfCard> 
@code{ 
    string CardSubTitle = "@harrisburg_keith"; 
    string base64 = Convert.ToBase64String(Model.ByteArray); 
    string CardImage = String.Format("data:image/gif;base64,{0}", base64); 


Kindly try the above solution and let us know if you need further assistance. 

Regards, 
Balasubramanian S 



FR Frank December 15, 2020 04:44 PM UTC

Thanks for your response.

That solution did not work for me.  The url for the image seems to be correct but the image is not displayed.

Below is a screen shot from the browser tools.  Note that for some reason the image data in the rightmost panel is show crossed-out.  This may be a clue?

I hope you can determine what is wrong.
 
Thanks again for your help,
Frank




BS Balasubramanian Sattanathan Syncfusion Team December 16, 2020 03:22 PM UTC

Hi Frank, 

Thanks for the reply. 

We have analyzed your shared details and prepared a sample based on that for your reference which can be downloaded from the below link. In the below sample, the card header will be displayed without an image on initial loading. Once the image has been added through the uploader, the uploaded image will be placed to the card header like the below screenshot. Here, the card image is the base64 byte data, not an URL. So we would suggest you to refer and follow the below sample. 

<CardHeader Title="Harrisburg Keith" SubTitle="@CardSubTitle" ImageUrl=@CardImage /> 

string CardImage = ""; 

public async Task onChange(UploadChangeEventArgs args) 
    files = new List<fileInfo>(); 
    this.selectedFiles = args.Files; 
    foreach (var file in args.Files) 
   
        var pathToSave = Path.Combine(Directory.GetCurrentDirectory(), "Images"); 
        var fullPath = Path.Combine(pathToSave, file.FileInfo.Name); 
        byte[] bytes = file.Stream.ToArray(); 
        string base64 = Convert.ToBase64String(bytes); 
        CardImage = String.Format("data:image/gif;base64,{0}", base64); 
        files.Add(new fileInfo() { Path = @"data:image/" + file.FileInfo.Type + ";base64," + base64, Name = file.FileInfo.Name, Size = file.FileInfo.Size }); 
        content = new MultipartFormDataContent { 
                { new ByteArrayContent(file.Stream.GetBuffer()), "\"upload\"", file.FileInfo.Name } 
            }; 
        filepath = await Http.PostAsync("https://localhost:44395/api/SampleData/Save", content); 
   
 
Screenshot: 
 

Kindly refer to the above solution and let us know if you need further assistance. 

Regards, 
Balasubramanian S 



FR Frank January 6, 2021 10:55 PM UTC

Sorry for taking so long to get back to you.   Below (sorry it is so messy) is a <CardHeader> that contains an ImageUrl="data:image;base64 .....

After that is a plain HTML <img> tag with the src=data:image;base64 .....   Exactly the same base64 series of bytes as for the ImageUrl in the <CardHeader>

The image in the CardHeader is not displayed.  The exact same image in the <img src=data:image ...> is displayed correctly.

If you can make sense of what I am saying,  I think this demonstrates that the <CardHeader ImageUrl="data:image;base64 ...   does not display the image.  I think there really is something wrong.


 <CardHeader Title="@trade.FullName()" SubTitle="@trade.Description" ImageUrl="data:image;base64, /9j/4AAQSkZJRgABAQEAAAAAAAD/4QBCRXhpZgAATU0AKgAAAAgAAYdpAAQAAAABAAAAGgAAAAAAAkAAAAMAAAABAAcAAEABAAEAAAABAAAAAAAAAAAAAP/bAEMACwkJBwkJBwkJCQkLCQkJCQkJCwkLCwwLCwsMDRAMEQ4NDgwSGRIlGh0lHRkfHCkpFiU3NTYaKjI+LSkwGTshE//bAEMBBwgICwkLFQsLFSwdGR0sLCwsLCwsLCwsLCwsLCwsLC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AB5UH/PKP/vhf8KPKg/55R/8AfC/4UUUAPVUXhVCj0UAD9KWiigD/2Q==" class="img-fluid" style="width:50px; height:50px" />



BS Balasubramanian Sattanathan Syncfusion Team January 7, 2021 08:22 AM UTC

Hi Frank, 

Thanks for the reply. 

As we mentioned in our last update, we can use base64 byte data to the ImageUrl. Since it is working properly at our end. So we would suggest you to check your base64 data whether it has generated properly or not. And if the problem is not resolved at your end, kindly share the issue reproduced sample to provide a prompt solution. 

Regards, 
Balasubramanian S 



FR Frank January 9, 2021 11:54 PM UTC

I have provided you (attached) with sample code that demonstrates the error.

Regards,
Frank

Attachment: DemoOfProblem_cb2e8dc5.zip


BS Balasubramanian Sattanathan Syncfusion Team January 11, 2021 10:54 AM UTC

Hi Frank, 

Thanks for the update. 

We have validated your shared sample at our end and let you know that you need to mention the image format in the base64 string as a below highlighted code snippet. We have added the base64 string in ImageUrl and checked. Since it is working properly at our end. So we would suggest you to add the image type and check whether the given code is saved in DB with its type properly.  

<SfCard> 
    <CardHeader Title="Fig 1" SubTitle="NOTE - No image is shown" ImageUrl="data:image/png;base64,iVBORw0…………." /> 
    <CardContent> 
Card Content 

    </CardContent> 
</SfCard> 


Kindly refer to the above sample and let us know if you need further assistance. 

Regard, 
Balasubramanian S


FR Frank January 11, 2021 02:56 PM UTC

Thank you for your response.

Here is what I can say definitively
1.  There is no need to specify the file type - the following works fine "ImageUrl="data:image;base64,iVBORw0KGgoAAAANSUhEUgAAARAAAABcCAYAAA...
2.  There is no problem using a .png file. Files of type .png work
3.  There is a problem using jpg files.  Files of type .jpg do not work

The example I provided you shows the problem using a jpg file.  It is reproducible.

Regards,
Frank


BS Balasubramanian Sattanathan Syncfusion Team January 12, 2021 10:33 AM UTC

Hi Frank, 

Thanks for the update. 

We have validated your reported problem at our end and let you know that you have provided space after the comma(,) due to this, the image is not displayed in the DOM. We have corrected the base64 string as shown below. So we would suggest you to use the below string in your project to display the image 

<SfCard> 
    <CardHeader Title="Fig 1" SubTitle="NOTE - No image is shown" ImageUrl="data:image;base64,/9j/4AAQSkZJRgABA….." /> 
    <CardContent> 
Card Content 

    </CardContent> 
</SfCard> 


Kindly try the above solution and let us know if this is helpful. 

Regards, 
Balasubramanian S

Marked as answer

FR Frank January 12, 2021 02:47 PM UTC

Hello,

Yes, you are correct.  This was entirely my sloppy error. I apologize and I thank you very much.

Regards,
Frank


NR Nevitha Ravi Syncfusion Team January 13, 2021 04:42 AM UTC

Hi Frank, 

Thanks for your update. 

We are happy that your issue has been resolved, please get back to us if you need any further assistance. 

Regards, 
Nevitha 


Loader.
Up arrow icon