Upload attachment to SharePoint list item using Microsoft Flow

Microsoft Flow is one of the Microsoft offerings for automation. In this series will see how to upload a file to SharePoint ListItem using MSFlow

Workflow for our scenario

Login to Microsoft Flow site and log in to create a new flow.

Add action and Type 'Data Operations' connector.

Then choose 'Data operations - Compose' action


Select 'Expression' tab and enter the following to create 'ListName' variable


Repeat this process for all other variables 
  • ListName - SharePoint list name.
  • ItemID     - SPList item ID.
  • AttachmentContent - Actual attachment content.
  • FileName - Attchment name.

Expressions: we can read values from Query String will discuss how to pass them next article.

ListName:
trigger()['outputs']['queries']['listname']

ItemID:
trigger()['outputs']['queries']['itemid']

Attachment Content:
triggerMultipartBody(0)['$content']

fName: - FileName
replace(split(string(split(string(json(concat(triggerOutputs()['body']['$multipart'][0]['headers'],''))['Content-Disposition']),';')[2]),'=')[1],'"','')


Flow will look like this after the above steps

Add 'SharePoint' connector then select 'SharePoint-GetAttachments'

Add ListName & ID from the dynamic variables


Now 'Add a condition' action to check the count > 0

length(body('Get_attachments'))


perform following

Delete attachment - action

Add attachment - action

With this setup, we are good to upload any file to the dynamically configured list item. in next article will see How to upload file via MS Flow endpoint using Javascript and PowerApps integration to this MS Flow using Swagger a.k.a OpenApi. I recommend reading the PowerApps scratch development seriesAzure Function integration with PowerApps and What is Microsoft Flow.

-Ratsub

Comments

  1. I have question on this post as When you are doing HTTP post request from Postman, how you are gathering data? HTTP POST request just returns status code. So I am wondering we are doing data operation on which data?

    ReplyDelete

Post a Comment

Enter your comments..

Popular posts from this blog

People picker Control in PowerApps

Secure When a HTTP request is received Power Automate a.k.a MS Flow

Modern page provisioning using page template

REST call returns XML instead of JSON in SharePoint

HTML field & Date Time formatting in powerapps

Step-By-Step Azure AD App Registration

Approval and auto escalation with time out in Microsoft Flow

Create and configure custom connectors for PowerApps and MSFlow from AzureFunctions

Developing custom reusable components in PowerApps