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 / Image property issue
Power Apps
Suggested Answer

Image property issue

(2) ShareShare
ReportReport
Posted on by 8

Urgent Issue:

I am using Power Apps to capture images and store them in a SharePoint folder. I use the built-in Camera control to capture images in .png format, send the image to an Attachment control, and then submit the form. The images were being saved correctly in the desired SharePoint folder earlier.

 

However, for the past two days, the captured images are getting corrupted. The files are being saved with a size of less than 2 KB and cannot be opened or viewed.

 

Please let me know why this issue is occurring and how it can be resolved.

Categories:
I have the same question (0)
  • WarrenBelz Profile Picture
    155,840 Most Valuable Professional on at
    Some details on your process steps and the code (in Text please) used would be very useful to look into this further.
  • DR-10090506-0 Profile Picture
    8 on at
    In my app user will fill some inputs through dropdown control and text control and add pictures from camera control to attachment control as using collection variables (bcoz user may add 1-20 images) at a time. Once submit using flow it will stored in SP folder.
  • Haque Profile Picture
    3,653 on at
    Hi @DR-10090506-0
     
    I suspect two areas:
     
    1. Incorrect image format or encoding - Probably, the camera control gives output an image as a base64-encoded string. If this string is not properly converted to a binary file before uploading, the file can be corrupted.

    2. Misuse of either Patch function or attachment control: If we send the base64 string directly to SharePoint without converting it to a file content type, SharePoint may save an invalid file.

    Let's go for two steps solution:

    Step-1: Please use JSON and Mid functions to extract the base64 content properly: As the Camera control's Photo property returns a data URI like "data:image/png;base64,iVBORw0KGgoAAAANS...", we need to remove the prefix before sending to destination (SP).

    Step-2: Please use Patch with Attachments field properly:  Let's convert the base64 string to binary data and send it as an attachment.

     

    I am assuming Save/Upload button is used and on it's OnSelect event we can formulate this below code:

    //--Let's extract base64 string without prefix
    Set(
        varImageBase64,
        Mid(
            Camera1.Photo,
            Find("base64,", Camera1.Photo) + 7,
            Len(Camera1.Photo)
        )
    );
    
    //--Build a collection with the attachment content in binary format
    
    ClearCollect(
        colAttachments,
        {
            Name: "CapturedImage.png",
            ContentBytes: JSON(varImageBase64, JSONFormat.IncludeBinaryData)
        }
    );
    
    //--Submit the form or patch the item with colAttachments as the attachment source
    
    SubmitForm(Form1);
    

     

    1. varImageBase64 stores the pure base64 string without the "data:image/png;base64," prefix.
    2. colAttachments is a collection with one record containing the file name and the binary content converted from base64.
    3. Lastly, it is assumed that the form’s attachment control should be bound to colAttachments or we can use colAttachments in a Patch function to upload the image.
     
     
    If it helps - here is the Patch function if you don't bind the control:
     
    Patch(
        'SPList',
        Defaults('SPList'),
        {
            Title: "ItemTitle", // other fields as needed
            Attachments: Table(
                {
                    Name: "CapturedImage.png",
                    ContentBytes: JSON(
                        Mid(Camera1.Photo, Find("base64,", Camera1.Photo) + 7, Len(Camera1.Photo)),
                        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!
  • DR-10090506-0 Profile Picture
    8 on at
    Camera control onselect property - 
    Collect(
        colFiles,
        {
            ContentBytes: Camera1.Photo,
            Name: txtidentifier.Value & "_" & ddpacktype.Selected.Value & "_" & Text(Now(), "yyyymmddhhmmss") & ".png"
        }
    )


    Submit code 
     
    If(
        CountRows(Attachmentcontrol.Attachments) = 0,
        Notify(
            "Please attach at least one image",
            NotificationType.Warning
        ),
        ForAll(
            Attachmentcontrol.Attachments,
            LogiMage_V2.Run(
                ddbu.Selected.Value,
                txtidentifier.Value,
                ddpacktype.Selected.Value,
                {
                    name: ddbu.Selected.Value & "_" & txtidentifier.Value & "_" & ddpacktype.Selected.Value & "-" & Text(
                        Now(),
                        "yyyymmdd_hhmmss"
                    ) & "." & Last(
                        Split(
                            ThisRecord.Name,
                            "."
                        )
                    ).Value,
                    contentBytes: ThisRecord.Value
                }
            )
        );
        Notify(
            "Photos uploaded successfully",
            NotificationType.Success
        )
    )
     
     
    Need to change app structure or flow structure?
     
  • Suggested answer
    WarrenBelz Profile Picture
    155,840 Most Valuable Professional on at
    I do something similar, but with an attach picture control - the output of both this and the camera are the same, so this should work for you. Firstly, you do not need to do any JSON / Base64 conversion here - the PowerApps V2 Trigger can handle a file natively - you only needed that conversion before this trigger was implemented as few years back - you also do not need the attachment control.
     
    You can add this into your existing code - I am sure you will get the idea.
    Collect(
       colFiles,
       {
          Photo: {
             file: {
                name: txtidentifier.Value & "_" & ddpacktype.Selected.Value & "_" & Text(Now(), "yyyymmddhhmmss") & ".png",
                contentBytes: Camera1.Photo
             }
          }
       }
    );
    Now the Flow run
    ForAll(
       colPhotos As _Files,
       LogiMage_V2.Run(_Files.Photo)
    )
    and the Flow
     
     
    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  
  • Haque Profile Picture
    3,653 on at
    Hi @DR-10090506-0,
     
    I was following up on this issue, is it resolved?
  • WarrenBelz Profile Picture
    155,840 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