Showing results for 
Search instead for 
Did you mean: 
Regular Visitor

Limiting the count and size of attachment in list item SPO


I am trying to limit the attachments in the app, even though I used the properties to accept 3 attachments, and the size is 2 mb, but still the app is accepting more than 3 attachments and larger size (5+).

Also, if there is any properties, that can control the attachments type, which needed only photos (jpg).


Helper I
Helper I

Hi Muhittin,


Just testing this for you now and I've had the expected behaviour occur for me:

To confirm, I've used a form connected to a SharePoint list, using the "Attachments" data card as-is.


Limiting the attachment size:





Limiting attachments:




There may be something with your control that's not playing ball with this configuration.


Now, for limiting attachment types, this isn't built into the PowerApps attachment tool. However; there is *a* way of doing it, sort of.


It's clunky and I've found Office Documents don't expose their File Extension, so this does work with image files if that's what you're looking to achieve:




I have an example form with one item: Attachments:



I also have the following:

  • Custom Message box to prompt user that file extension is invalid (Two rectangles, label and button. Grouped together with visibility controlled with a boolean Variable (msg)
  • Collection to store Attachments (Referencing the control doesn't work, for some reason)



This formula is attached to the Attachment Control under "OnAddFile". We collect the attachments, then set the msg boolean variable is the last attachment contains a key word (We're using png, you can expand this out for your needs.


When attaching a jpeg:




When attaching a png:



Formula attached to the "Ok" button removes the last attachment in the attach collection therefore limiting the file extensions:



As mentioned before, this isn't fool proof but probably the best you can get in PowerApps for now.


@sgtsnacks Thanks for your reply, the first part is ok now, I was limiting the display layer, where I should do it for the edit layer. 😉

Regarding to the example that you did , I am not sure that I understand it quite well , you are allowing jpg only , or allowing png file, what I am aiming to is to allow only photos, since the usage of this SPO's list will be done through mobile phone, and its camera, and don't want the user to upload other types of files , such as pdf, docx, etc. 


Helper I
Helper I

Hi Muhittin,


To confirm, in my example I'm allowing all files except PNG.


ClearCollect(attach,DataCardValue4.Attachments);Set(msg,"png" in Last(attach.Name).Name)


The last section controls this filtering. If you wanted to limit to just photos, the filter would look something like this:


ClearCollect(attach, DataCardValue4.Attachments);
Set(msg,Not("png" in Lower(Last(attach.Name).Name) || "jpg" in Lower(Last(attach.Name).Name) || "jpeg" in Lower(Last(attach.Name).Name)))

Above is untested, but should prevent any file unless it's "png", "jpg" or "jpeg"


You can adjust the filtering to anything you require specifically. Just remember not all files display an extension so this solution isn't completely fool-proof.


I found this code online, did the job , but when I take 2 photos and then upload 1 pdf, it reset the box and remove all attachments .


Not(".jpg" in Name) And Not(".jpeg" in Name) And Not(".png" in Name),
{Name: Name}
CountRows(collIncorrectExtension) > 0,
"Only Photos Allowed",

This code is resetting the control (last line). You should have it remove last item in collection as per my example.

@sgtsnacks there is something went wrong, and I am unable to find it out, kindly update the above code in full shape, so I can see, test and learn the correct one.

Helpful resources

Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

365 EduCon 768x460.png

Microsoft 365 EduCon

Join us for two optional days of workshops and a 3-day conference, you can choose from over 130 sessions in multiple tracks and 25 workshops.

Users online (1,612)