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

Notifications

Announcements

Community site session details

Community site session details

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

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:
I have the same question (0)
  • Verified answer
    WarrenBelz Profile Picture
    153,030 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
    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
    on at

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

  • WarrenBelz Profile Picture
    153,030 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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 796 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 327 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard