Creating a custom connector to upload a file to Google Drive from Power Apps – Part 1
Knowing the limitation
Although Power Automate (Microsoft Flow) and Power Apps support ready-to-use connectors for different services, it seems they do not have the same level of offerings between them.
In Flow, for instance, there is a connector for Google Drive and there is a bunch of actions like creating/deleting a file, browsing the folder.
However, you cannot use those actions in Power Apps. Apparently, Google Drive connector in Power Apps only works for excel as a datasource.
Additionally, if you pay attention to different image controls, such as PenInput, Camera, Add Media, they have different properties which looks like they are doing the same thing. For example, Camera.Photo returns a Data URI of a picture, while PenInput.Image and AddMediaButton.Media effectively returns a local blob storage URL (appres://blobmanager/<GUID>/<serial number>) which can only be accessed in the app.
Combining with the inability of using full functionality of connectors and meaningless local blob storage URL outside the app, we need look at what else we can do.
Knowing the out-of-box capability
Given that Camera.Photo returns a Data URI string of an image, we can convert it into binary and save it into Google Drive. However, it has another small issue. Camera control in Power Apps does not use the full resolution of device camera. It is ridiculously small (at least to me). If even we can live with small photos, we still need a workaround for other controls.
Out-of-the-box, you can upload images from above control to Azure Blob Storage. Then, from Azure Blob Storage, you can copy the file to the destination you want. This is not a problem for a client who has already had Azure subscription, but not a neat solution for a client who has no prior Azure subscription. Trust me the cost is never a problem (Azure Blob Storage is super cheap) but it’s more about managing different instances. If managing different instances is not an issue, this is a way to go.
Going an extra mile
This is where a real fun starts.
But, we always want to go an extra mile to see what else there. In the bright side, Power Apps allows us to create a custom connector which can be configured in Flow to upload a file to Google Drive.
First, let’s start with creating a flow which will be triggered when HTTP request is received. There is only one trigger available. This is basically a webhook.
Then, initialise the ‘FileName’ variable, so we can save the flow. The expression for value is trigger()[‘outputs’][‘queries’][‘filename’] as we are planning to pass query string filename during the request.
After saving the flow, expand the HTTP trigger point to grab the URL to invoke
Copy that URL to Postman, and append filename query string in URL. Please note sig query string should be kept in secret.
After invoking the URL, you will see the Flow is executed. When you open the execute Flow instance, you will see the filename query string is assigned to FileName variable in Flow.
Now, let’s try sending the file from Postman and let’s look at the Flow to extract file content. In your Postman, choose File form-data and send the request.
Open the executed flow. This time, you will see ‘click to download’ in the output of HTTP request.
When you open it, you will see a massive output, but we are only after for a few things which are body and $content. $content is Base64 of uploaded file.
To get this content, add another variable initialiser. This time we are going to set its type as Object, as Google Drive accepts JSON.
Now, let’s add another action to upload a file to Google Drive. It will ask you to connect to Google if you have no prior connection.
Now, let’s choose the folder path in Google Drive, file name and its content. You will need to write an expression for file content to get the object of FileContent variable.
Save the Flow. Go back to Postman, and send the request. You will see the flow is executed and a file is uploaded to your Google Drive.
I will cover the process of converting this Flow into a custom connector and calling it directly from Power Apps, in Part 2.
Creating a custom connector to upload a file to Google Drive from Power Apps – Part 1