I had a requirement to upload a document to the SharePoint document library (integrated with the Account entity in dynamics CE) from the power apps portal, the portal supports uploading and displaying SharePoint documents as documented here ( by placing the document location subgrid on a portal basic/advance form), but our requirement was to allow portal users to upload documents only to specific folders.

For achieving this specific requirement, I have used an Html file uploader and a power automate flow that receives the request and creates a file in the SharePoint document library specific folder.

The file uploader HTML code snippet, that I have used.

<div class="input-group">
    <input id="pathInput" type="text" class="form-control" readonly value="/account/<abc>/<xyz>/Building Notices" />
    <input id="fileInput" type="file" class="form-control" />
    <button id="btnUploadFile" type="button" class="btn btn-primary">
        Add Document
    </button>
</div>

The JS code that I used for posting the form-data with “mimeType”: “multipart/form-data”, to my power automate flow.

$(document).ready(function () {
const btnUploadFile = document.getElementById('btnUploadFile');
const fileInput = document.getElementById('fileInput');
const pathInput = document.getElementById('pathInput');
btnUploadFile.addEventListener('click', () => {
    if (fileInput.files.length > 0) {
        var form = new FormData();
        form.append("fileContent", fileInput.files[0]);
        form.append("fileName", fileInput.files[0].name);
        form.append("folderPath", pathInput.value);

        var settings = {
            "url": "",
            "method": "POST",
            "timeout": 0,
            "processData": false,
            "mimeType": "multipart/form-data",
            "contentType": false,
            "data": form
        };

        $.ajax(settings).done(function (response) {
            console.log(response);
        });
    }
});
});


Following is the power automate flow that, triggers When a HTTP request is received.


For convenience 😋 one can copy the expression below.

base64ToString(triggerFormDataValue('fileName')['$content'])
base64ToString(triggerFormDataValue('folderPath')
base64ToBinary(triggerFormDataValue('fileContent')['$content'])

A successful run output.


After a successful run, the file is added to the specific document library folder.

siddiquemahsud
Author: siddiquemahsud

2 responses to “Upload a file to SharePoint document library using Power automate Flow”

  1.  Avatar
    Anonymous

    Good

  2.  Avatar
    Anonymous

    awesome, I will call you when I needed to do such kind of work

Leave a Reply

Your email address will not be published. Required fields are marked *