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).
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:
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:
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.
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),
CountRows(collIncorrectExtension) > 0,
"Only Photos Allowed",
@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.
This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.
Come together to explore latest innovations in code and application development—and gain insights from experts from around the world.
At the monthly call, connect with other leaders and find out how community makes your experience even better.