cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Muhittin
Regular Visitor

Limiting the count and size of attachment in list item SPO

Greetings,

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).

Regards.

6 REPLIES 6
sgtsnacks
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:

sgtsnacks_0-1637068500612.png

Property:

sgtsnacks_1-1637068512911.png

 

Limiting attachments:

sgtsnacks_2-1637068570952.png

Property:

sgtsnacks_3-1637068598960.png

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:

 

sgtsnacks_4-1637070266116.png

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)

 

sgtsnacks_6-1637070855886.png

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:

 

sgtsnacks_4-1637070266116.png

 

When attaching a png:

sgtsnacks_7-1637070966081.png

 

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

sgtsnacks_8-1637071131714.png

 

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. 

Regards.

sgtsnacks
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.

@sgtsnacks 

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 .

 

Clear(collIncorrectExtension);
ForAll(
DataCardValue10.Attachments.Name,
If(
Not(".jpg" in Name) And Not(".jpeg" in Name) And Not(".png" in Name),
Collect(
collIncorrectExtension,
{Name: Name}
)
)
);
If(
CountRows(collIncorrectExtension) > 0,
Notify(
"Only Photos Allowed",
NotificationType.Error
);
Reset(Self)
)

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

Announcements
PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

Microsoft Build 768x460.png

Microsoft Build is May 24-26. Have you registered yet?

Come together to explore latest innovations in code and application development—and gain insights from experts from around the world.

May UG Leader Call Carousel 768x460.png

What difference can a User Group make for you?

At the monthly call, connect with other leaders and find out how community makes your experience even better.

Top Solution Authors
Top Kudoed Authors
Users online (3,710)