cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
rjm
Level: Powered On

Partial solution for uploading PDF files from PowerApps to SharePoint through Flow

Hello,

Looking around the internet it seems that many people struggle with using PowerApps to upload non-image files to SharePoint. Most tutorials out there show you how to do so with camera images, but this does not work for files that you pull from SharePoint.  

Here's why. When PowerApps passes any file from SharePoint to Flow, it does so with a BLOB (Binary Large OBject) reference (e.g. appres://blobmanager/55de916dfa7f4640b243dbd822208afd). As far as I understand, this can't even be converted from binary since it's just a reference. Flow doesn't seem to be able to do anything with this. I could not find any way to get PowerApps to send the file in a different format - with one exception.

PowerApps does have an Add Picture control, which allows you to upload a picture from your computer. As it turns out, you can add any file with this control so long as you add it to a collection and treat it like an image (e.g. ContentBytes: UploadedImage1.Image). Shane Young's tutorial was useful for this. Below is the OnSelect code for the PowerApps button that triggers the flow that uploads the file to SharePoint:

file upload button code.PNG

Collections are stored as tables, and I found that I have to concatenate the ContentBytes column in PowerApps before sending it to Flow. This (mis)use of the Add Image control gets PowerApps to send the PDF's file content to Flow as a base64 file, which I then can convert using the base64ToBinary() function. I then have a Flow that is set up to receive input from PowerApps and then send the input as an email. For some reason you have to set the Flow to request input from PowerApps specifically for an email attachment. If you do this, PowerApps will send the file content as "format": "byte"; if you instead set the Flow up to request data for a Create File in SharePoint action, it will send the file content as "format": "binary" (the BLOB file reference). 

flow sp uploader code.PNG

So far, so so. Now I have a way to upload a file from my desktop to an Add Image control PowerApps, and I have a button that sends the file name and file content to Flow in base64. Flow then takes the file, converts to binary, and adds it to SharePoint. However, I have not found a way to do this without having to also send the file as an email attachment. If I delete the Send an Email action, I get the following error:

InvalidTemplate. Unable to process template language expressions in action 'Create_file' inputs at line '1' and column '2568': 'The template language expression 'json(decodeBase64(triggerOutputs().headers['X-MS-APIM-Tokens']))['$connections']['shared_sharepointonline']['connectionId']' cannot be evaluated because property 'shared_sharepointonline' doesn't exist, available properties are 'shared_office365'.

It appears that I have to keep the Send an Email action in there in order to trick PowerApps and Flow into continuing to send the file content of my PDF as a base64 file.

Does anyone have any insights as to how I can make this work without having to send an email each time a file is uploaded? My team wants to scale this solution to cover all of our SharePoint file uploads, and right now the amount of junk email generation this would imply means that it's not workable. My hope is that Microsoft will soon roll out native functionality in PowerApps so that users can upload more than just camera images to SharePoint (imagine that!).

Cheers,

rjm

 

Also, I noticed something very strange with the base64ToBinary() function. When I enter in into the Flow, at first it is visible. Then, as soon as I navigate away from editing the Flow, it seemingly disappears. But then if I look in the Peek Code section, it's still there! Very weird. 

base64 disappearance flow.png

1 ACCEPTED SOLUTION

Accepted Solutions
rjm
Level: Powered On

Re: Partial solution for uploading PDF files from PowerApps to SharePoint through Flow

Props to John Liu for figuring this one out. It's so obvious in retrospect - all you have to do is add a condition that always evaluates to false (when 0 equals 1) and park the Send Email action in the 'if true' branch. That way no email is sent but the Send Email action is still there so that the data is pulled from PowerApps in the proper format.

3 REPLIES 3
Community Support Team
Community Support Team

Re: Partial solution for uploading PDF files from PowerApps to SharePoint through Flow

Hi @rjm ,

 

Thank you for sharing, maybe you could try the following methods to improve the solution.

  1. Delete Send an email action and save the current Flow, and export the Flow as a .zip file.
  2. Then re-import it as a new Flow, after configuring the connection, see if the problem you mentioned still exists.

In addition, the expression is displayed as Dynamic content, which is the result of automatic generation of Flow. There are a lot of similar situations.

For example, the following d.id is actually body('Get_the_user_Principal_Id')['d']['id']

We could use peek code to get the initial expression.

13.PNG

Hope this helps.

 

Best Regards,

Community Support Team _ Barry
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
rjm
Level: Powered On

Re: Partial solution for uploading PDF files from PowerApps to SharePoint through Flow

Hi Barry, I did actually try reimporting the Flow, but the problem persists.

 

Thanks for outlining all that below. I'm a bit confused though as to what you mean - when you write about using peek code to find the initial expression, what part of the issue I outlined are you referring to exactly?

rjm
Level: Powered On

Re: Partial solution for uploading PDF files from PowerApps to SharePoint through Flow

Props to John Liu for figuring this one out. It's so obvious in retrospect - all you have to do is add a condition that always evaluates to false (when 0 equals 1) and park the Send Email action in the 'if true' branch. That way no email is sent but the Send Email action is still there so that the data is pulled from PowerApps in the proper format.

Helpful resources

Announcements
firstImage

Microsoft Business Applications Virtual Launch Event

Watch the event on demand for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.

firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

Power Platform 2019 Release Wave 2 Plan

Power Platform 2019 Release Wave 2 Plan

Features releasing from October 2019 through March 2020.

thirdimage

Flow Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

sixthImage

Power Platform World Tour

Find out where you can attend!

seventhimage

Webinars & Video Gallery

Watch & learn from the Flow Community Video Gallery!

Top Kudoed Authors
Users Online
Currently online: 468 members 4,796 guests
Please welcome our newest community members: