Retrieve Files from Upload File question
Within Microsoft Forms it is possible to include an upload file question. In this article I will show you how to retrieve the uploaded file(s) via a Power Automate flow.
Inspiration
This question from cristineisles:
Essentially I have an MS Forms where users will fill out the information for approval/rejection. In that form, they will be able to add attachments (1/more). I am running into this issue at the moment: For Get file content using path, the path does exist.
Power Users Community thread: PLEASE HELP – Get file content using path error.
Upload File question json
Like any other question it is possible to retrieve the answer of such an upload file type of question. The Get response details action is the one you want to use. However, that response comes with a couple of challenges.
First of all it returns a string array with properties like name, link, etc. Those properties are useful, but if you try and reference with an expression you could run into Property selection is not supported on values of type ‘String’ error.
Below is an example of such an expression in a Compose action and the error it returns.
The Get Response details action returns a string and not an array. You can use a json function to workaround this.
The below is an updated expression which uses that json function to convert the upload file question from a string to an array. And after that you can retrieve the first item with an index [0] and reference link property of that first item.
Groups vs Personal Forms
Before we figure out how to retrieve the uploaded files it is good to take one step back.
For Microsoft Forms the file storage location of the uploaded file(s) depends on what type of form you are using, a Group hosted versus a Personal form. This will make difference for our approach, so make sure you figure out what type of form you are dealing with.
A Group hosted form will store the uploaded file(s) in the Documents library of the SharePoint site of the related group.
A personal form will store the uploaded file(s) in the OneDrive for Business site of the person who created the form.
In this case we are going to look into a Groups form. Keep in mind that with a personal form you can simply use the id property of that array in a Get File Content (OneDrive for Business connector).
Doc.aspx Link with GUID
Retrieving the location of the files uploaded in a Groups form question from the answer array is the second challenge. Although this array returns a link property, this is not a link to a direct link to the file location. It is a link to Doc.aspx application page of Microsoft with a GUID of the file in a sourcedoc query parameter.
However, it does return a file GUID, which is pretty useful. You can use a Get File by Id method to get more details of the file. I have shared this approach before in the Get File by Id (Guid) blog. With an indexOf function we can locate the sourcedoc parameter and with a substring function we can retrieve the value.
Flow Setup
For this sample I am using Groups Microsoft Form, for a Groups add form id as a custom value because it won’t be listed in the Form Id dropdown.
1. Add a When a new response is submitted action.
a. Select your form from the dropdown, in this case add the Groups form id as a custom value.
2. Add a Get response details action.
a. Select your form from the dropdown, in this case add the Groups form id as a custom value.
b. Provide a Response Id, use the Response Id field from the Dynamic Content.
3. Add a Apply to Each action.
a. Use the below expression as the Select an output from previous steps. Make sure you update the question id in this example to your own question id.
4. Add a Send an HTTP request to SharePoint action.
a. Use the below expression as the SiteAddress.
b. Use the GET method
c. Use the URI from the code snippet below
d. Use the Headers from the code snippet below
5. Add a Get File Content using Path action.
a. Use the below expression as the SiteAddress.
b. Use the below expression as the File Path.
6. Add a Create File action.
a. Select a Site Address, in the case I used a different target site .
b. Select a Folder Path, I used a Audit Documents library.
c. Provide a File Name, use the name.
d. Provide the File Content, use the Body of the Get File Content using path action.
7. Add a Update file properties action.
a. Select a Site Address, in the case I used a different target site .
b. Select a Library Name, I used a Audit Documents library.
c. Provide a Id, use the ItemId of the Create File action.
d. Provide some additional file properties, in this example I used the Response Id and Responders’ Email in two separate fields of the library.
That should be it for the setup.
Happy testing!