web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Corrupt attachment sav...
Power Apps
Answered

Corrupt attachment saved in Sharepoint list

(2) ShareShare
ReportReport
Posted on by 6,501
Hello Everyone.
 
I have an app in power apps. 
 
Its an old app where form control is used to submit the form.
 
In that there is an attachment control. On Add Property I am adding file details to a collection, file name and Value.
 
But when I am doing this, instead of file content, blob storage reference is coming.
 
After submitting the form I am sending this collection to power automate which saves the attachment in attachment field of sharepoint list.
 
But because of this blob storage reference files are stored as corrupted.
 
Anyone else who has faces this issue before. Or if more details are required, please let me know.
Categories:
I have the same question (0)
  • Suggested answer
    Haque Profile Picture
    3,653 on at
    Hi @Sundeep_Malik
     
    What you need to do is convert blob to Base64 in PA:
    We can use Attachment Control’s Attachments Property - the attachment control’s Attachments property contains an array of files with properties including Name and Value. The Value is often a blob reference. Instead of sending the entire collection directly, send the file names and base64 content to Power Automate.
     
    Here we go:
    // Assuming AttachmentsControl is your attachment control
    Set(varFileBase64, JSON(First(AttachmentsControl.Attachments), JSONFormat.IncludeBinaryData))
     

    I am sure some clues I tried to give. If these clues help to resolve the issue brought you by here, please don't forget to check the box Does this answer your question? At the same time, I am pretty sure you have liked the response!
  • Sundeep_Malik Profile Picture
    6,501 on at
    Hey @Haque
     
    I tried it but this doesnt work. I wrote the below code on Add:
     
    ClearCollect(
        CollAttachment5,
        ForAll(
            Self.Attachments,
            {
                Name: Name,
                Value: JSON(Value, JSONFormat.IncludeBinaryData)
            }
        )
    )
     
    But it automatically takes blob storage only.
     
  • Haque Profile Picture
    3,653 on at
     
    Once your collection is ready, how do you save the file? I saw you are using flow.
     
    Could you please check if this tutorial helps or not? It saves file, but image will work too.
  • Suggested answer
    Kalathiya Profile Picture
    2,456 Super User 2026 Season 1 on at
    Hello @Sundeep_Malik
     
    Yes, if the file content is not valid, the attachment may become corrupted and will not open properly.
     
    You can follow the steps below:

    #1. Create a Power Automate flow with a File input parameter for the attachment.

    #2. Add a SharePoint – Add attachment action (or Create file if you want to store it in a document library).

    Copy below expression and past in File Name and File Content: 

    File Name: 

    @{triggerBody()['file']['name']}

    File Content:

    @{triggerBody()['file']['contentBytes']}

    #3. In Power Apps, add the flow and use it to upload the attachment to the SharePoint list or document library.

     
    Upload Button Code - OnSelect Property: 
    ForAll(
            AttachmentControlName.Attachments As _obj, 
                UploadAttachment.Run(
                        {
                            file: {
                                    contentBytes: _obj.Value,
                                    name: _obj.Name
                                }
                        }
                )
    );
    
    //UploadAttachment- Replace with your Automate name - This is the automate name 
    //AttachmentControlName - Replace with your attachment control name
    It will upload all the attachments one by one that the user has added in the Attachment control.
     
    Similar Reference blog for more details: 
     
    If this response resolves your issue, please mark it as the Verified Answer so it can help other community members as well.
    ---------------------------------------------------------------------------------
     
    📩 Need more help? Mention @Kalathiya anytime!
    ✔️ Don’t forget to Accept as Solution if this guidance worked for you.
    💛 Your Like motivates me to keep helping!
     
  • Verified answer
    WarrenBelz Profile Picture
    155,838 Most Valuable Professional on at
    Firstly what you have from @Haque and @Kalathiya is one direction you can take and in particular @Kalathiya's post should work.
     
    I am suggesting another simpler solution if (from what I can interpret) you want to send some attachments to a SharePoint List record. Put a Form on the Screen in New Mode (you can hide it if you want to) with the DataSource as the SharePoint list and add an attachment control. In the Items put (using your control name)
    AttachmentControlName.Attachments
    You did not mention if the SharePoint record was a new or updating an existing record - I will do an existing one below. If a new record use Defaults(SPListName), instead of the LookUp.
    Patch(
       SPListName,
       LookUp(
          SPListName,
          YourLookupHere
       ),
       {
          Field1: Yourvalue
          Field2: YourValue
          . . . . . 
       },
       YourNewFormName.Updates
    )
    NOTE: If you are not using your existing attachment control for anything else, there is no need for the second one - just use the original inside a Form and reference it in the Patch.
     
    Please Does this answer your question if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider answering Yes to Was this reply helpful? or give it a Like
    Visit my blog
    Practical Power Apps    LinkedIn  
  • Sundeep_Malik Profile Picture
    6,501 on at
    Thanks for the help all there :)
     
    Solutions provided by both @Haque and @Kalathiya were correct but my scenario was a little different.
     
    @WarrenBelz, this was the scenario I was referring to and your solution worked.
     
    I am not really sure why it was adding blob storage in contents, because of which when I was trying to save the attachment with a flow it was saving it as corrupt.
     
    But the patch code worked great.
     
    Initially when I tested it, it worked fine. But when I submitted the attachments again it was showing this error:
     
    Network error when using Patch Function, Field ID is Required.
     
    Then I researched a little, at the end I added ResetForm and it did work. Any clue @WarrenBelz, why did it show this error. In Patch I am just using Form.Updates and updating the attachment, I have only kept attachment control in the new form.
     
    But for now ResetForm did fix it, not sure permanently or not.
     
    Currently keeping this post open only, for about a week, if any issues are reported and if no issues are reported, I will mark @WarrenBelz's answer as the solution, though all the three answers are valid solutions only.
     
    Thanks for the help all three.
     
    :)
     
    Really appreciate it.
  • WarrenBelz Profile Picture
    155,838 Most Valuable Professional on at
    Firstly, are you creating a new record in SharePoint or adding the attachments to an existing record? If a new record, are you populating any other fields ?

    Can you please post (in Text) the exact code you are using. Also using ResetForm (on the new hidden form) before the patch is something I maybe should have suggested (so please do it) and will take care of the next record the user does.
     
    Please Does this answer your question if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider answering Yes to Was this reply helpful? or give it a Like
    Visit my blog
    Practical Power Apps    LinkedIn  
     
  • Sundeep_Malik Profile Picture
    6,501 on at
    Hello @WarrenBelz,
     
    I am adding/removing attachments from an existing record. I have another form for creating a new record, that works perfectly fine.
     
    Code on Submit button:
     
    If(
        !IsBlank(ItemID),
        Patch(
            'Document_SPList',
            LookUp(
                'Document_SPList',
                Contract_ID = ItemID
            ),
            Form8.Updates
        )
    );ResetForm(Form8);
     
    In the new form I just have attachment field.
     
    To remove removed attachments, I have a flow running.
  • WarrenBelz Profile Picture
    155,838 Most Valuable Professional on at
     
    So this is now solved ?
     
    Please Does this answer your question if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider answering Yes to Was this reply helpful? or give it a Like
    Visit my blog
    Practical Power Apps    LinkedIn  
  • WarrenBelz Profile Picture
    155,838 Most Valuable Professional on at
    A quick follow-up to see if you received the answer you were looking for. Happy to assist further if not.
     
    Please Does this answer your question if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider answering Yes to Was this reply helpful? or give it a Like ♥
    Visit my blog
    Practical Power Apps    LinkedIn   

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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Valantis Profile Picture

Valantis 424

#2
WarrenBelz Profile Picture

WarrenBelz 355 Most Valuable Professional

#3
11manish Profile Picture

11manish 290

Last 30 days Overall leaderboard