PowerAutomate - Upload a PDF file from Sharepoint to an ASP.NET endpoint

Create an ASP.NET endpoint:


 [HttpPost("upload_pdf")]

 public async Task<IActionResult> UploadPdf()

 {

     var uploadsPath = Path.Combine(Directory.GetCurrentDirectory(), "UploadedFiles");

     if (!Directory.Exists(uploadsPath))

         Directory.CreateDirectory(uploadsPath);


     var fileName = $"uploaded_{DateTime.UtcNow:yyyyMMdd_HHmmss}.pdf";

     var filePath = Path.Combine(uploadsPath, fileName);


     using (var stream = new FileStream(filePath, FileMode.Create))

     {

         await Request.Body.CopyToAsync(stream);

     }

     return Ok(new { message = "File uploaded successfully", fileName = fileName });

 }


Open Power Automate to create a new flow.


Step 1: Add a Sharepoint trigger "When a file is created (properties only)" and set the Site Address, Library Name.

(Note: Returns only the properties stored in the library columns. You can add a "Get file content" step and use the "File identifier" property returned by this action to get to the contents of the file)


Step 2: Add a "Get file content" action, add the Identifier:




or type the expression: triggerBody()?['{Identifier}']


Step 3: Add an HTTP action


Headers:
Content-Type: application/pdf

Body: File content



IMPORTANT: turn off Allow chunking






The entire flow:





No comments:

Theme images by merrymoonmary. Powered by Blogger.