I created a Power Automate flow that performs an HTTP GET request to download a PDF file and save it to Sharepoint.
The filename is in the output of the HTTP headers with Content-Disposition
header equal to something like attachment; filename=\"EXAMPLE_FILENAME.pdf\"
. In order to get the filename, I use the following function to extract EXAMPLE_FILENAME.pdf
split(outputs('HTTP')['headers']?['Content-Disposition'],'"')[1]
However, if the filename has a special symbol (like É), Content-Disposition
has a value of attachment; filename*=UTF-8''EXAMPLE_FILENAME_%C3%89.pdf
, and the logic I had before does not work because there is no "
to split by.
How can I extract the filename from both Content-Disposition
formats? Ideally I am not adding more steps in my flow and I have one function that can accomodate both formats.
I ended up just creating an if statement to check if the filename contains filename=
if(
contains(outputs('HTTP')['headers']?['Content-Disposition'],'filename='), # Check
split(outputs('HTTP')['headers']?['Content-Disposition'],'"')[1], # No special character
decodeuricomponent(split(outputs('HTTP')['headers']?['Content-Disposition'],'''''')[1]) # Special character (UTF-8)
)