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

Partial solution for uploading PDF files from PowerApps to SharePoint using 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 using Flow

Flow was actually how I solved the issue, and I simply hijacked the Add Image control.

 

I also found out how to solve my problem. 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.

View solution in original post

2 REPLIES 2
K-A-R-L
Level 10

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

Hi @rjm ,

Since you want to save files from PA to SP you might need to use the apps to avoid any complicated configuration in Flow.

Please be advised that attachment control only works insidea a form (not gallery).

Please read this.

 

Thanks,
K-A-R-L


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 using Flow

Flow was actually how I solved the issue, and I simply hijacked the Add Image control.

 

I also found out how to solve my problem. 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.

View solution in original post

Helpful resources

Announcements
thirdimage

Power Apps Super User Class of 2020

Check it out!

thirdimage

New Badges

Check it out!

thirdimage

Power Apps Community User Group Member Badge

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

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

SecondImage

Difinity Conference

The largest Power BI, Power Platform, and Data conference in New Zealand

Top Solution Authors
Top Kudoed Authors
Users online (4,344)