Power Automate Flow Uploads Corrupted Files (4 Bytes) to SharePoint After Working Properly Initially

Vaibhav Sapkota 0 Reputation points
2024-10-31T12:03:41.1366667+00:00

I’ve built a Power Automate flow to handle email attachments by saving them to SharePoint and generating a shareable link. Initially, this flow worked without issues, saving attachments with full content to SharePoint. Recently, however, the attachments are saved as corrupted files with only 4 bytes.

  1. Here’s a detailed breakdown of the issue and troubleshooting steps: Steps and Observations
    1. Flow Overview:
    • Trigger: When a new email arrives (V3).
    • Process: Retrieve attachments from email, save them to SharePoint under the folder /OriginalAttachments, and generate a share link.
      • File Content Configuration: I use the contentBytes expression for the File Content parameter. (Photo 1)
        photo1
    1. Current Issue:
      • Recently, the flow began saving attachments as corrupted files with a size of only 4 bytes. When attempting to preview these files on SharePoint, I receive an "Unable to preview file" error. (Photo 2).
        photo2
      • Upon inspection in SharePoint, I noticed that newly saved files are 4 bytes in size, while some previously saved files (from when the flow was functioning properly) retain their original sizes. (Photo 3)
        photo3
    2. Troubleshooting Steps Taken:
    • Testing Other Flows: I recreated the flow in a premium account, where it worked initially. However, similar issues eventually appeared.
      • Checked contentBytes Output:
      • In flows where the files are corrupted, contentBytes returns null. (Photo 4).
        photo4
      • In flows where files save correctly, contentBytes returns the expected content as base64. (Photo 5).
        photo5
      • Using Compose to Inspect Outputs:
      • The corrupted flow outputs resemble: {...} (Photo 6).
        photo6
      • The correct flow outputs resemble: {base64 content...} (Photo 7).
        photo7
      1. Additional Attempts:
        - Tried       using contentId, attachmentId, and other attachment properties, but files       continue saving as 4 bytes.
        
    Questions:
    1. What could cause contentBytes to return null intermittently in this context, despite the same file and flow configuration?
    2. Are there specific settings or account limitations that could lead to attachments being saved as 4-byte corrupted files?
    3. Any recommended fixes to ensure attachments consistently save with their full content in SharePoint?
SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
10,796 questions
Not Monitored
Not Monitored
Tag not monitored by Microsoft.
39,617 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Joe Kempster 0 Reputation points
    2024-11-01T09:04:36.46+00:00

    I found this link on a different post. https://tomriha.com/how-to-avoid-corrupt-email-attachment-in-power-automate/

    I used expression below instead of contentBytes directly and this has solved my problem where I was getting corrupted files in SharePoint, maybe this will help with your issue.

    base64ToBinary(item()?['contentBytes'])
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.