在Logic Apps中从HTTP二进制输出生成PDF并保存到SharePoint的问题
Let's break down why your current approaches aren't working and walk through the correct steps to get that PDF saved properly to SharePoint:
Why Your Previous Attempts Failed
- When you pass
body('HTTP')directly, you're sending the entire HTTP response object (including headers, status code, and nested body structure) instead of just the raw PDF data. SharePoint can't parse this into a valid file. body('HTTP')?['content']targets the wrong property—your actual content lives inbody('HTTP')?['$content'], which is an Atom XML feed string, not direct binary PDF data.- Using
base64ToBinary()without setting the correct content type makes SharePoint default toapplication/octet-stream, which doesn't tell the system it's a PDF, hence the opening error.
Step-by-Step Solution
Extract the Atom XML Content
First, grab the XML string from the HTTP response's$contentproperty:body('HTTP')?['$content']Parse XML to Get Base64-encoded PDF Data
Use Power Automate'sxpathandxmlfunctions to extract the base64 string representing your PDF from the Atom feed. The PDF data is typically stored inside the<content>tag of the feed's entry. Use this expression:first(xpath(xml(body('HTTP')?['$content']), '//content/text()'))xml(...)converts the string into an XML object Power Automate can query.xpath(..., '//content/text()')fetches all text inside<content>tags (this is your base64 PDF data).first(...)picks the first result (since there should only be one PDF entry in the feed).
Convert to Binary and Save to SharePoint
When using SharePoint's Create file action:- Set the File Content field to:
base64ToBinary(first(xpath(xml(body('HTTP')?['$content']), '//content/text()'))) - Expand the Advanced options section and set Content Type to
application/pdf.
- Set the File Content field to:
This ensures you're passing the correct binary PDF data and telling SharePoint exactly what type of file it is, so it will save and open properly as a PDF.
内容的提问来源于stack exchange,提问作者Neo

