Show image base64 string in a row

Show image base64 string in a row

MolaxMolax Posts: 3Questions: 2Answers: 0

Hi, I want to build a DataTable that shows a image on the frist row, but I receive an object from the ajax like this

Object
FK_SIZE: 4
FK_TYPE: 2
NAME: "Skol Lata"
PHOTO: (Base64 string too long to put in here)

When I put the Data on the DataTable like this code

                $('#drinkTable').DataTable({
                    data: data,
                    columns: [
                        { data: 'PHOTO' },
                        { data: 'NAME' },
                        { data: 'FK_TYPE' },
                        { data: 'FK_SIZE' }
                    ]
                });

the table shows the base64 string -> http://prntscr.com/92x3rp

I would like to show the image that the string represents

This question has an accepted answers - jump to answer

Answers

  • jLinuxjLinux Posts: 981Questions: 73Answers: 75
    Answer ✓

    Theres no JS library or jQuery function that can render an image from the Base64 encoded string... that needs to be done on the server side. Definitely not something handled by DataTables..

  • MolaxMolax Posts: 3Questions: 2Answers: 0

    Thank you ! I put this code on back-end

    ```

            foreach (var item in Drinks)
            {
                item.PHOTO = String.Format("<div align=center><img src='{0}' width='50' vspace='5'></div>", item.PHOTO);
            }
    
            return Drinks;
    

    ```

    then the data went to the front exaclty how i wanted, now it works fine, thanks for the tip.

This discussion has been closed.