Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Automate - Using Flows
Answered

PDF Corrupted in Sharepoint

(0) ShareShare
ReportReport
Posted on by

I created a flow to grab a PDF attachment from an email when one arrives and save it in a Sharepoint document library. The file is created correctly but it cannot be previewed or opened in Adobe Acrobat. The attachments can be opened just fine when I open them through the email. When I try to open it in Adobe, it gives this error:

Capture.PNG

 

Here are screenshots of my flow. I omitted the middle section but it is just variable manipulation and shouldn't have any impact on the file content. Any help is appreciated!

Capture1.PNG

Capture2.PNG

  • traceyannspence Profile Picture
    29 on at
    Re: Corrupted files after createfile in Sharepoint

    Thank you I appreciated it. Turns out it was just a really dumb mistake as I forgot to add the "get file content" to ummm... well... get the correct content?

  • traceyannspence Profile Picture
    29 on at
    Re: Corrupted files after createfile in Sharepoint

    UPDATE lol... this was exactly my problem. It works perfectly now with get content added in .... don't even need the binary function.

  • traceyannspence Profile Picture
    29 on at
    Re: Corrupted files after createfile in Sharepoint

    I think I've *almost* figured this out 🙂
    this is the gist of my flow that takes files from Onedrive and uploads to SP and then updates the properties with data from a spreadsheet. 
    I think I need to add a "get file content" in before the create file step... maybe with some combination of using the binary formula

    traceyannspence_0-1716818808286.png

    I'll keep you posted :).

  • ZERAREZ Profile Picture
    28 on at
    Re: Corrupted files after createfile in Sharepoint

    Hi,

     

    It's been a while but yes, I was able to resolve this just not sure which part I made an update. Below are the parts of the flow I made, hope it'll help:

     

    I first set a condition to specify what file types I am looking for. I ad to do this to avoid creating files for all items included in the email. 

    ZERAREZ_0-1716774921211.png

     

    Then, the next step is to have the flow rename the items to be uploaded in SharePoint following a define format:

     

    ZERAREZ_1-1716775039888.png

    Get Attachment Name: 

    first(split(variables('rename attachment'), '.'))
     
    Get Attachment Extension:
    last(split(variables('Rename Attachment'), '.'))
     
    Compose:
    concat(outputs('Get_Attachment_Name'), '_', formatDateTime(convertFromUtc(utcNow(), 'Singapore Standard Time'), 'MMddyyyy hh:mm'), '.', outputs('Get_Attachment_Extension'))
     
    Then just create a file in SP:
    ZERAREZ_2-1716775214078.png

    I believe the update I did that fix the corrupted error was defining the file types I needed.

  • traceyannspence Profile Picture
    29 on at
    Re: Corrupted files after createfile in Sharepoint

    I got this error message when I put that formula in (changed "apply_to_each_2" to "apply_to_each")

     

    InvalidTemplate. Unable to process template language expressions in action 'Create_file' inputs at line '0' and column '0': 'The template language function 'base64ToBinary' expects its parameter to be a string. The provided value is of type 'Null'. Please see https://aka.ms/logicexpressions#base64ToBinary for usage details.'.

     

    traceyannspence_0-1716683214656.png

     

    THANK YOU!!

  • abm abm Profile Picture
    32,464 Most Valuable Professional on at
    Re: Corrupted files after createfile in Sharepoint

    Hi @traceyannspence 

     

    Try the below

     

    image.png

     

    base64ToBinary(items('Apply_to_each_2')?['contentBytes'])

  • traceyannspence Profile Picture
    29 on at
    Re: Corrupted files after createfile in Sharepoint

    Did you resolve this. I'm having similar issue. the PDF file uploads through flow from onedrive and the file is fine on onedrive and is corrupt on SharePoint.

  • ZERAREZ Profile Picture
    28 on at
    Re: Corrupted files after createfile in Sharepoint

    Hi,

     

    I believe I am encountering the same issue; however, in all file types. 

     

    My initial goal is to simply upload copies of all email attachments to a specific SharePoint Document Library. I was able to do that but the files being created automatically are all corrupted/non-functional and 4 bytes in size.

     

    ZERAREZ_0-1633720712012.png

    ZERAREZ_1-1633720726088.png

     

    I have tried a work around re: base64ToBinary(items('Apply_to_each')?['contentBytes']); however, it's giving me a 'Null' error. I'm not sure where to go from here after searching the web for possible fixes and failing.

     

    ZERAREZ_2-1633720883228.png

     

    Appreciate any help,

     

    Neil

     

  • abm abm Profile Picture
    32,464 Most Valuable Professional on at
    Re: PDF Corrupted in Sharepoint

    Hi @Anonymous 

     

    Thanks for the update. Glad that you found the issue. The signature file names are fixed so you could check that in an IF condition to exclude those.

     

    Thanks

  • Community Power Platform Member Profile Picture
    on at
    Re: PDF Corrupted in Sharepoint

    @abm I changed the file name from my custom name to the original file name using dynamic content and this time it created 3 files at once in Sharepoint--the PDF (which can now be opened!) and two images which were part of the signatures in the test email I was forwarding.

     

    I deleted the signatures in the test email and tried again with my custom file name and the images are no longer created and the PDF can be opened now.

     

    I guess if you're unknowingly capturing multiple attachments at once, you won't know it unless you keep all dynamic content the same in the Create File action. 

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Markus Franz – Community Spotlight

We are honored to recognize Markus Franz as our April 2025 Community…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,670 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 66,011 Most Valuable Professional

Leaderboard

Featured topics

Restore a deleted flow