{"id":342,"date":"2022-12-23T11:41:44","date_gmt":"2022-12-23T11:41:44","guid":{"rendered":"http:\/\/4us2use.at\/?p=342"},"modified":"2022-12-23T12:01:30","modified_gmt":"2022-12-23T12:01:30","slug":"patch-powerapps-attachment-to-sharepoint-library","status":"publish","type":"post","link":"http:\/\/4us2use.at\/?p=342","title":{"rendered":"Patch PowerApps Attachment to SharePoint Library"},"content":{"rendered":"\n<p>Pr<strong>oblem: <\/strong><\/p>\n\n\n\n<p>You can&#8217;t easily patch a file (any filetype) directly to a SharePoint Library (it&#8217;s different than working with a SharePoint list!). For this it takes several steps as a workaround.<\/p>\n\n\n\n<p><strong>Solution:<\/strong><\/p>\n\n\n\n<p>As a very first step create a new PowerApp and connect it with your library.<br>Secondly connect ANY SharePoint list to the app where attachments are enabled and embed an edit form for both lists.<\/p>\n\n\n\n<p><img loading=\"lazy\" width=\"339\" height=\"193\" class=\"wp-image-343\" style=\"width: 250px;\" src=\"http:\/\/4us2use.at\/wp-content\/uploads\/2022\/12\/sources.png\" alt=\"\" srcset=\"http:\/\/4us2use.at\/wp-content\/uploads\/2022\/12\/sources.png 339w, http:\/\/4us2use.at\/wp-content\/uploads\/2022\/12\/sources-300x171.png 300w\" sizes=\"(max-width: 339px) 100vw, 339px\" \/>  <\/p>\n\n\n\n<p>In the form of the library add a custom data card and copy the attachment field from the list form to the empty custom data card &#8211; you can remove the error for &#8220;Parent.Default&#8221; by just deleting it. Afterwards you can also remove the data connection to the list and the related form since we just needed it temporary to copy over the attachment control. It should look simply like this:<br><img loading=\"lazy\" width=\"558\" height=\"326\" class=\"wp-image-344\" style=\"width: 300px;\" src=\"http:\/\/4us2use.at\/wp-content\/uploads\/2022\/12\/form01.png\" alt=\"\" srcset=\"http:\/\/4us2use.at\/wp-content\/uploads\/2022\/12\/form01.png 558w, http:\/\/4us2use.at\/wp-content\/uploads\/2022\/12\/form01-300x175.png 300w\" sizes=\"(max-width: 558px) 100vw, 558px\" \/><\/p>\n\n\n\n<p>Not the trick begins&#8230;<br>If you upload an attachment and check it&#8217;s value, you&#8217;ll just see a URI for a temporary blob storage like in my example: appres:\/\/blobmanager\/36446683a549421988f5b9f4b3bbdbb2\/1<\/p>\n\n\n\n<p>This format can not be used for further processing!<br>This is why we require a temporary image control.<br>Set the <strong>Image <\/strong>property of this control to: <br><em>L<\/em><strong><em>ast(fileUpload.Attachments).Value<\/em> <\/strong><br>(where fileUpload is the name of my attachment control)<\/p>\n\n\n\n<p>Now we need convert the output of the Image to a format we&#8217;ll be able to use later in a Power Automate Flow to create the file in the SharePoint library. For better understanding I&#8217;ll split the steps to not complicate the formula.<\/p>\n\n\n\n<p>In the <strong>OnAddFile <\/strong>property of the attachment add following formulas:<br>(if you place any label and set it&#8217;s Text property to the variable, you can see what happens)<br><strong>Set(varFileContent,JSON(imgTEMP.Image,JSONFormat.IncludeBinaryData))<\/strong>;<br><strong><em>Set(varFileStreamBase64,Mid(varFileContent,Find(&#8220;,&#8221;,varFileContent)+1));<br>Set(varFileStreamBase64Final,Substitute(varFileStreamBase64,&#8221;&#8221;&#8221;&#8221;,&#8221;&#8221;));<\/em><\/strong><\/p>\n\n\n\n<p>Explanation: <br>In the first line we extract the Base64 encoded file content.<br>Next we remove the beginning of the file until &#8220;&#8230;Base64,&#8221; &#8211; this is where the real file content starts.<br>Last but not least we&#8217;re removing the character &#8221; from the end of the file content string.<\/p>\n\n\n\n<p>Now we need a Flow &#8211; just create a new Flow out of your PowerApp like this:<br><img loading=\"lazy\" width=\"615\" height=\"795\" class=\"wp-image-347\" style=\"width: 600px;\" src=\"http:\/\/4us2use.at\/wp-content\/uploads\/2022\/12\/flow-1.png\" alt=\"\" srcset=\"http:\/\/4us2use.at\/wp-content\/uploads\/2022\/12\/flow-1.png 615w, http:\/\/4us2use.at\/wp-content\/uploads\/2022\/12\/flow-1-232x300.png 232w\" sizes=\"(max-width: 615px) 100vw, 615px\" \/><\/p>\n\n\n\n<p>Now we just need to add a button to test. <br>OnSelect: &#8216;<br><em><strong>Po<\/strong><\/em><strong><em>werApps-UploadFileToSharePointLIBRARY&#8217;.Run(Last(fileUpload.Attachments).Name, varFileStreamBase64Final)<\/em><\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"433\" height=\"365\" src=\"http:\/\/4us2use.at\/wp-content\/uploads\/2022\/12\/finalApp.png\" alt=\"\" class=\"wp-image-350\" srcset=\"http:\/\/4us2use.at\/wp-content\/uploads\/2022\/12\/finalApp.png 433w, http:\/\/4us2use.at\/wp-content\/uploads\/2022\/12\/finalApp-300x253.png 300w\" sizes=\"(max-width: 433px) 100vw, 433px\" \/><\/figure>\n\n\n\n<p>That&#8217;s it &#8211; I hope you enjoy and buy me a beer \ud83d\ude09<\/p>\n\n\n\n<span id=\"post-ratings-342\" class=\"post-ratings\" data-nonce=\"a56bd8e9c9\"><img id=\"rating_342_1\" src=\"http:\/\/4us2use.at\/wp-content\/plugins\/wp-postratings\/images\/stars\/rating_off.gif\" alt=\"1 Star\" title=\"1 Star\" onmouseover=\"current_rating(342, 1, '1 Star');\" onmouseout=\"ratings_off(0, 0, 0);\" onclick=\"rate_post();\" onkeypress=\"rate_post();\" style=\"cursor: pointer; border: 0px;\" \/><img id=\"rating_342_2\" src=\"http:\/\/4us2use.at\/wp-content\/plugins\/wp-postratings\/images\/stars\/rating_off.gif\" alt=\"2 Stars\" title=\"2 Stars\" onmouseover=\"current_rating(342, 2, '2 Stars');\" onmouseout=\"ratings_off(0, 0, 0);\" onclick=\"rate_post();\" onkeypress=\"rate_post();\" style=\"cursor: pointer; border: 0px;\" \/><img id=\"rating_342_3\" src=\"http:\/\/4us2use.at\/wp-content\/plugins\/wp-postratings\/images\/stars\/rating_off.gif\" alt=\"3 Stars\" title=\"3 Stars\" onmouseover=\"current_rating(342, 3, '3 Stars');\" onmouseout=\"ratings_off(0, 0, 0);\" onclick=\"rate_post();\" onkeypress=\"rate_post();\" style=\"cursor: pointer; border: 0px;\" \/><img id=\"rating_342_4\" src=\"http:\/\/4us2use.at\/wp-content\/plugins\/wp-postratings\/images\/stars\/rating_off.gif\" alt=\"4 Stars\" title=\"4 Stars\" onmouseover=\"current_rating(342, 4, '4 Stars');\" onmouseout=\"ratings_off(0, 0, 0);\" onclick=\"rate_post();\" onkeypress=\"rate_post();\" style=\"cursor: pointer; border: 0px;\" \/><img id=\"rating_342_5\" src=\"http:\/\/4us2use.at\/wp-content\/plugins\/wp-postratings\/images\/stars\/rating_off.gif\" alt=\"5 Stars\" title=\"5 Stars\" onmouseover=\"current_rating(342, 5, '5 Stars');\" onmouseout=\"ratings_off(0, 0, 0);\" onclick=\"rate_post();\" onkeypress=\"rate_post();\" style=\"cursor: pointer; border: 0px;\" \/> (No Ratings Yet)<br \/><span class=\"post-ratings-text\" id=\"ratings_342_text\"><\/span><\/span><span id=\"post-ratings-342-loading\" class=\"post-ratings-loading\"><img src=\"http:\/\/4us2use.at\/wp-content\/plugins\/wp-postratings\/images\/loading.gif\" width=\"16\" height=\"16\" class=\"post-ratings-image\" \/>Loading...<\/span>\n","protected":false},"excerpt":{"rendered":"<p>Problem: You can&#8217;t easily patch a file (any filetype) directly to a SharePoint Library (it&#8217;s different than working with a SharePoint list!). For this it takes several steps as a workaround. Solution: As a very first step create a new PowerApp and connect it with your library.Secondly connect ANY SharePoint list to the app where &hellip; <\/p>\n<p class=\"link-more\"><a href=\"http:\/\/4us2use.at\/?p=342\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Patch PowerApps Attachment to SharePoint Library&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[11,6],"tags":[],"_links":{"self":[{"href":"http:\/\/4us2use.at\/index.php?rest_route=\/wp\/v2\/posts\/342"}],"collection":[{"href":"http:\/\/4us2use.at\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4us2use.at\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4us2use.at\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4us2use.at\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=342"}],"version-history":[{"count":5,"href":"http:\/\/4us2use.at\/index.php?rest_route=\/wp\/v2\/posts\/342\/revisions"}],"predecessor-version":[{"id":352,"href":"http:\/\/4us2use.at\/index.php?rest_route=\/wp\/v2\/posts\/342\/revisions\/352"}],"wp:attachment":[{"href":"http:\/\/4us2use.at\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=342"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4us2use.at\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=342"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4us2use.at\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=342"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}