{"id":38688,"date":"2024-07-22T12:29:50","date_gmt":"2024-07-22T06:59:50","guid":{"rendered":"https:\/\/www.inogic.com\/blog\/?p=38688"},"modified":"2024-12-11T09:46:51","modified_gmt":"2024-12-11T04:16:51","slug":"attachment-control-in-power-apps-implementing-file-type-validation","status":"publish","type":"post","link":"https:\/\/www.inogic.com\/blog\/2024\/07\/attachment-control-in-power-apps-implementing-file-type-validation\/","title":{"rendered":"Attachment Control in Power Apps: Implementing File Type Validation"},"content":{"rendered":"<p><img decoding=\"async\" class=\"alignnone wp-image-38695 size-full\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2024\/07\/Attachment-Control-in-Power-Apps.png\" alt=\"Attachment Control in Power Apps\" width=\"1400\" height=\"800\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2024\/07\/Attachment-Control-in-Power-Apps.png 1400w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2024\/07\/Attachment-Control-in-Power-Apps-300x171.png 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2024\/07\/Attachment-Control-in-Power-Apps-1024x585.png 1024w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2024\/07\/Attachment-Control-in-Power-Apps-768x439.png 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2024\/07\/Attachment-Control-in-Power-Apps-660x377.png 660w\" sizes=\"(max-width: 1400px) 100vw, 1400px\" \/><\/p>\n<p style=\"text-align: justify;\">I recently came across a client requirement to create a candidate registration system integrated using canvas apps. The client, a third-party hiring company, wanted to securely store candidate details and along with their resumes in CRM. They specifically asked for uploaded files to be limited to formats such as JPG, docx, or PDF due to security concerns. Allowing unrestricted file uploads poses significant risks, including the potential for malicious files like .exe to execute harmful actions, compromise sensitive data, or harm systems.<\/p>\n<p style=\"text-align: justify;\">To address this issue, I conducted thorough research and discovered methods for implementing file type validation in the Power Apps&#8217; attachment control. This ensures that only approved file extensions are allowed, thereby reducing security risks and protecting the application&#8217;s integrity and data.<\/p>\n<p style=\"text-align: justify;\"><strong>Below is the approach to fulfil the client&#8217;s requirement to <\/strong>create a candidate registration system with users only able to attach restricted format files as resumes:<\/p>\n<p>1. After creating the canvas app, creating a table named \u201c<strong>Candidate<\/strong> <strong>Registrations<\/strong>\u201d and adding data from \u201c<strong>Candidate Registrations<\/strong>\u201d, my screen will look like the below screenshot.<\/p>\n<p><strong>Note<\/strong>: The fields you are seeing on the screen are the fields of the \u201c<strong>Candidate<\/strong> <strong>Registrations\u201d <\/strong>table.<\/p>\n<p><img decoding=\"async\" class=\"alignnone wp-image-38689 size-full\" style=\"border: 1px solid #000000; padding: 1px; margin: 1px;\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2024\/07\/Attachment-Control-in-Power-Apps-1.png\" alt=\"Attachment Control in Power Apps\" width=\"1917\" height=\"816\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2024\/07\/Attachment-Control-in-Power-Apps-1.png 1917w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2024\/07\/Attachment-Control-in-Power-Apps-1-300x128.png 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2024\/07\/Attachment-Control-in-Power-Apps-1-1024x436.png 1024w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2024\/07\/Attachment-Control-in-Power-Apps-1-768x327.png 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2024\/07\/Attachment-Control-in-Power-Apps-1-1536x654.png 1536w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2024\/07\/Attachment-Control-in-Power-Apps-1-660x281.png 660w\" sizes=\"(max-width: 1917px) 100vw, 1917px\" \/><\/p>\n<p>2. Now to validate the file extension as per the client\u2019s requirement, you need to add the below formula under the \u201c<em><strong>OnAddFile<\/strong><\/em><em>\u201d <\/em>property of your attachment control which will limit the uploaded file type.<\/p>\n<pre class=\"lang:css gutter:true start:1\">With(\r\n   {\r\n        RequiredExtensions: [\r\n            \".pdf\",\r\n            \".docx\",\r\n            \".jpg\"\r\n        ],\r\n       FileName: Lower(Last(Self.Attachments).Name)\r\n    },\r\n   If(\r\n          CountIf(\r\n            RequiredExtensions,\r\n            EndsWith(\r\n                FileName,\r\n                ThisRecord.Value\r\n            )\r\n        ) = 0,\r\n        Notify(\r\n            FileName &amp; \" is not allowed. You can add resumes only of \" &amp; Concat(\r\n                RequiredExtensions,\r\n                Value,\r\n                \", \"\r\n            ) &amp; \" formats\",\r\n            NotificationType.Error\r\n        )\r\n    )\r\n)\r\n<\/pre>\n<p><img decoding=\"async\" class=\"alignnone wp-image-38690 size-full\" style=\"border: 1px solid #000000; padding: 1px; margin: 1px;\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2024\/07\/Attachment-Control-in-Power-Apps-2.png\" alt=\"Attachment Control in Power Apps\" width=\"1917\" height=\"888\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2024\/07\/Attachment-Control-in-Power-Apps-2.png 1917w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2024\/07\/Attachment-Control-in-Power-Apps-2-300x139.png 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2024\/07\/Attachment-Control-in-Power-Apps-2-1024x474.png 1024w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2024\/07\/Attachment-Control-in-Power-Apps-2-768x356.png 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2024\/07\/Attachment-Control-in-Power-Apps-2-1536x712.png 1536w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2024\/07\/Attachment-Control-in-Power-Apps-2-660x306.png 660w\" sizes=\"(max-width: 1917px) 100vw, 1917px\" \/><\/p>\n<p>3. Click on <strong>Save<\/strong> and then click on <strong>Publish<\/strong> to save changes.<\/p>\n<p>4. Now if you open the \u201c<strong>Candidate Registration<\/strong>\u201d app on your tablet it will look like below attached screenshot.<\/p>\n<p><img decoding=\"async\" class=\"alignnone wp-image-38691 size-full\" style=\"border: 1px solid #000000; padding: 1px; margin: 1px;\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2024\/07\/Attachment-Control-in-Power-Apps-3.png\" alt=\"Attachment Control in Power Apps\" width=\"1483\" height=\"689\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2024\/07\/Attachment-Control-in-Power-Apps-3.png 1483w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2024\/07\/Attachment-Control-in-Power-Apps-3-300x139.png 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2024\/07\/Attachment-Control-in-Power-Apps-3-1024x476.png 1024w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2024\/07\/Attachment-Control-in-Power-Apps-3-768x357.png 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2024\/07\/Attachment-Control-in-Power-Apps-3-660x307.png 660w\" sizes=\"(max-width: 1483px) 100vw, 1483px\" \/><\/p>\n<p style=\"text-align: justify;\">Now, if you attempt to upload a file that is not of type pdf, docx, or jpg, you will receive an error.<\/p>\n<p><img decoding=\"async\" class=\"alignnone wp-image-38692 size-full\" style=\"border: 1px solid #000000; padding: 1px; margin: 1px;\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2024\/07\/Attachment-Control-in-Powr-Apps-4.png\" alt=\"Attachment Control in Power Apps\" width=\"698\" height=\"314\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2024\/07\/Attachment-Control-in-Powr-Apps-4.png 698w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2024\/07\/Attachment-Control-in-Powr-Apps-4-300x135.png 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2024\/07\/Attachment-Control-in-Powr-Apps-4-660x297.png 660w\" sizes=\"(max-width: 698px) 100vw, 698px\" \/><\/p>\n<h2 style=\"text-align: justify;\"><strong>Conclusion:<\/strong><\/h2>\n<p style=\"text-align: justify;\">The process described demonstrates how to validate attachments and restrict the upload of files to specific types in canvas apps. This is valuable for ensuring that only files with specific file types are uploaded, reducing security risks and protecting the application&#8217;s integrity and data.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I recently came across a client requirement to create a candidate registration system integrated using canvas apps. The client, a third-party hiring company, wanted to securely store candidate details and along with their resumes in CRM. They specifically asked for uploaded files to be limited to formats such as JPG, docx, or PDF due to\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.inogic.com\/blog\/2024\/07\/attachment-control-in-power-apps-implementing-file-type-validation\/\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":15,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[38,44],"tags":[2908],"class_list":["post-38688","post","type-post","status-publish","format-standard","hentry","category-microsoft-powerapps","category-power-apps","tag-file-type-validation"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/38688","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/users\/15"}],"replies":[{"embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/comments?post=38688"}],"version-history":[{"count":0,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/38688\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/media?parent=38688"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/categories?post=38688"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/tags?post=38688"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}