How can I add an icon representing a file type for a URL into a table?

Options

I have a data set which contains a column for URL's for file a user has upload and a second column that contains the type of file that has been uploaded. I have created a beast mode that displays a thumbnail of any uploads that are images. I now want to display an icon for items that are not images but cannot get the icons to display.

This is the beast mode that I have been using to display the thumbnails:

CONCAT('<a href="',`stepAnswerUploadUrl`,'" target="_blank">',
'<img src="',`stepAnswerUploadUrl`,'" height="20px" alt="Click for image"/>',
'</a>')

As a test I attempted to load a PDF icon for all non-image file types, using the following beast mode. The thumbnail worked for images but all other types were blank.

CASE
WHEN stepAnswerUploadType = 'IMAGE' THEN
CONCAT('<a href="',`stepAnswerUploadUrl`,'" target="_blank">',
'<img src="',`stepAnswerUploadUrl`,'" height="20px" alt="Click for image"/>',
'</a>')
ELSE
CONCAT('<a href="',`stepAnswerUploadUrl`,'" target="_blank">',
'<i class="fas fa-file-pdf"></i>',
'</a>')
END

Any assistance would be greatly appreciated

Tagged:

Best Answer

  • DavidChurchman
    Answer ✓
    Options

    I would probably still create a column that is either the link to the image or a link to an image that represents the file type, and then use that as the image source in the HTML Beastmode. (To me, it's harder to get HTML code right, so I want to keep that part of the code as simple as possible).

    But if you want to do it in your case statement, you just need a working img src, which is missing from that clause of your case statement:

    CASE
    WHEN stepAnswerUploadType = 'IMAGE' THEN
    CONCAT('<a href="',`stepAnswerUploadUrl`,'" target="_blank">',
    '<img src="',`stepAnswerUploadUrl`,'" height="20px" alt="Click for image"/>',
    '</a>')
    WHEN stepAnswerUploadType = 'PDF' THEN
    CONCAT('<a href="',`stepAnswerUploadUrl`,'" target="_blank">',

    '<img src=https://upload.wikimedia.org/wikipedia/commons/thumb/8/87/PDF_file_icon.svg/267px-PDF_file_icon.svg.png height="20px" alt="Click for file"/>',
    '</a>')
    END

    Please 💡/💖/👍/😊 this post if you read it and found it helpful.

    Please accept the answer if it solved your problem.

Answers

  • ColemenWilson
    Options

    I used:

    CASE
    WHEN stepAnswerUploadType = 'IMAGE' THEN
    CONCAT('<a href="',`stepAnswerUploadUrl`,'" target="_blank">',
    '<img src="',`stepAnswerUploadUrl`,'" height="20px" alt="Click for image"/>',
    '</a>')
    WHEN stepAnswerUploadType = 'PDF' THEN
    CONCAT('<a href="',`stepAnswerUploadUrl`,'" target="_blank">',
    '<img src="',`stepAnswerUploadUrl`,'" height="20px" alt="Click for image"/>',
    '</a>')
    END

    And get the following:

    Will that work for you?

    If I solved your problem, please select "yes" above

  • D_Markley34
    Options

    Thanks for the quick response. Unfortunately that does not work for me. The value in stepAnswerUploadUrl is the url for the actual file that was uploaded not an icon. The image works because it opens a thumbnail of the actual image.

  • DavidChurchman
    Options

    You're using `stepAnswerUploadUrl` to point towards the image icon and that's working? Why don't you add the url for your PDF icon to that same column so you don't need a CASE statement?

    Like all IMAGES, could have this url as their <img src>:

    And all PDFs could have this url as their <img src>:

    Please 💡/💖/👍/😊 this post if you read it and found it helpful.

    Please accept the answer if it solved your problem.

  • D_Markley34
    Options

    The stepAnswerUploadUrl contains the url of the actual item that was uploaded to the system not the url for the icon. Ideally, I would want to show a thumbnail of the uploaded file regardless of the file type, but am willing to settle for the icon of the file type if it is not an image.

    DaveTestImage contains this beast mode calculation:

    CASE
    WHEN stepAnswerUploadType = 'IMAGE' THEN
    CONCAT('<a href="',`stepAnswerUploadUrl`,'" target="_blank">',
    '<img src="',`stepAnswerUploadUrl`,'" height="20px" alt="Click for image"/>',
    '</a>')
    ELSE
    CONCAT('<a href="',`stepAnswerUploadUrl`,'" target="_blank">',
    '<i class="fas fa-file-pdf"></i>',
    '</a>')
    END

  • DavidChurchman
    Answer ✓
    Options

    I would probably still create a column that is either the link to the image or a link to an image that represents the file type, and then use that as the image source in the HTML Beastmode. (To me, it's harder to get HTML code right, so I want to keep that part of the code as simple as possible).

    But if you want to do it in your case statement, you just need a working img src, which is missing from that clause of your case statement:

    CASE
    WHEN stepAnswerUploadType = 'IMAGE' THEN
    CONCAT('<a href="',`stepAnswerUploadUrl`,'" target="_blank">',
    '<img src="',`stepAnswerUploadUrl`,'" height="20px" alt="Click for image"/>',
    '</a>')
    WHEN stepAnswerUploadType = 'PDF' THEN
    CONCAT('<a href="',`stepAnswerUploadUrl`,'" target="_blank">',

    '<img src=https://upload.wikimedia.org/wikipedia/commons/thumb/8/87/PDF_file_icon.svg/267px-PDF_file_icon.svg.png height="20px" alt="Click for file"/>',
    '</a>')
    END

    Please 💡/💖/👍/😊 this post if you read it and found it helpful.

    Please accept the answer if it solved your problem.

  • D_Markley34
    Options

    Thanks that does work