In this blog, i will explain how you can upload files directly from Power Apps to SharePoint Document Library, you can even use this method for other proposes like add files as attachment or create files in OneDrive. You will need
1- Power App
2- SharePoint Document Library Access
3- Power Automate

So lets get started.

First You Need to Extract a Form Attachment Element, Just add a New Form and Attach any SharePoint List. The Form auto populate Data Fields, Add the Attachment Field yourself if its not present. Now Unlock the Attachment Data Card and Just Select the Attachment Data Card Value, Copy it and Paste it Outside the Form, you can delete the Form now its not Required.

Copy and Paste the Attachment Card Outside Form and Delete the Form

Now Set the Errors on the Attachment Card.
BorderColor: Any Color you prefer (i.e. Color.Black)
Items: Remove Code
Tooltip: Remove Code (Optional: Add Any Yourself)
DisplayMode: Edit

Now the Data Card is Set. Now for the Next Step.

Add an Image Control and Set it to,

Now add a Button and Convert this Image to Json and include binary data in a Variable, Add the variable in a label so you can see the Value.

As you can see its converted, but now we need to Remove Extra Text from the Converted JSON Binary Data, Till base64, AND the inverted Commas at End. Use the Following formula and it should look like this,

Set(VarBase64Only, Mid(VarFromAttachmentControl , Find(“,”,VarFromAttachmentControl) + 1, Len(VarFromAttachmentControl) – Find(“,”,VarFromAttachmentControl)-1));

You Can delete the Labels after this. Not Required only for show.

Next Step is to Create a Flow with trigger from Power App, Create File in SharePoint.
In Create a File, for name and file content use Ask from Power Apps.
for File Content wrap the Ask from Power App Variable in base64tobinary expression i.e. base64ToBinary(triggerBody()[‘Createfile_FileContent’])

Now go to your Power App and on a New Button or on the Same one Attach your newly Created Flow and add the 2 Arguments, Name and The VarBase64Only Variable (Or of any other name if you Changed). Then it Should look like this,

And That’s All, Upload Away 🙂