web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Detect type of file in...
Power Apps
Answered

Detect type of file in a gallery to show images

(0) ShareShare
ReportReport
Posted on by

Hi, 

Once an item is created, i have a screen in power apps with a gallery that shows me all the items and once clicked it goes to another screen that show more details of that item. One of those details is an attachment field but i replaced it for a gallery (to have kinda like a small img preview),  so in the gallery i show all the attachments for that item that can be btwen 1-4 max attachments, the attachments can be of any type in the img control in the gallery it shows perfect if the attachments are img type but if it is another type of file like pdf etc is blank and i have 4 img control in the gallery for all the attachments depending on the amount but since max is 4 im using 4 img controls in the gallery. I need to write in the img control a conditional to check like if the display Name of the attachment is an img type if yes show the imgs attached but if is another type of file to show an img i uploaded in the power app to be like a default img.

All that i found is only for is only one image but i need to do it like in plural, for all the attachments not the first or like that

this code for example:

If(
Last(Split(First(DisplayItem.Attachments).DisplayName,".")).Value = "jpg" ||
Last(Split(First(DisplayItem.Attachments).DisplayName, ".")).Value = "png" ||
Last(Split(First(DisplayItem.Attachments).DisplayName, ".")).Value = "jpeg",
ThisItem.AbsoluteUri,
'file-icon-vector-illustration'
)

 

it will always only check on the first (checked on the output and the display name is always only the first one)

 

other one that i tried was something like this ;

If(
Last(Split(First(ThisItem.Attachments).DisplayName, ".")).Result in ["jpg","png","jpeg"],
First(ThisItem.Attachments).Value,
SampleImage
)

But it also does not work is always for an item only.

 

could anyone help me?

Thanks,

Categories:
  • Verified answer
    WarrenBelz Profile Picture
    156,956 Most Valuable Professional on at

    Hi @MarTorres07 ,

    You could try this

    If(
     EndsWith(ThisItem.DisplayName,"jpg") ||
     EndsWith(ThisItem.DisplayName,"png") ||
     EndsWith(ThisItem.DisplayName,"jpeg"),
     ThisItem.Value,
     'file-icon-vector-illustration'
    )

    but this may be better (using your domain name)

    "https://yourdomainname.sharepoint.com/_layouts/15/getpreview.ashx?path=" & ThisItem.AbsoluteUri

     

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

    MVP (Business Applications)   Visit my blog Practical Power Apps

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Hi Warren, thanks for your reply, I'm the original op from another account (since it doesn't let me access the first one no idea why).

    I tried your solution with the domain name, but the gallery is just blank .. I don't know what I'm doing wrong? I also found a video of reza that kind of does the same but still it just doesn't show anything for me in the gallery.

    In the gallery items: i have  ThisItem.attachments. because the gallery is inside a an edit form to see the details of the item. and i just want to show the attachments of that item. and then in the image control i have this : "https://TTTStudioRequestTool.sharepoint.com/_layouts/15/getpreview.ashx?path="& ThisItem.AbsoluteUri . And is just not showing enaything

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Never mind, i fixed it there was something worng on the url i used but thank you so much!

  • WarrenBelz Profile Picture
    156,956 Most Valuable Professional on at

    Hi @Anonymous ,

    The code is for the image, not the gallery Items 

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 243 Super User 2026 Season 2

#2
WarrenBelz Profile Picture

WarrenBelz 204 Most Valuable Professional

#3
Mohsin Ali Profile Picture

Mohsin Ali 122

Last 30 days Overall leaderboard