cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
ITBird
New Member

Encoding image files in a collection to Base64?

Hi all, 

 

I have a screen on my app where a user can capture multiple photos. These photos are collected into a collection named 'CameraPhotos' and displayed in a gallery. When the submit button is pressed, I need to save the images as Base64 strings (perhaps in to another collection or add a column in CameraPhotos?). The base64 strings will then be patched to the sql server with the rest of the collections at the end.

 

Can anyone help me with this one? I'm not sure how I achieve this in Powerapps?

1 ACCEPTED SOLUTION

Accepted Solutions
KvB1
Solution Specialist
Solution Specialist

I'm sorry, I made a mistake. You don't need the image control in order to convert to Base64, so the solution is a lot simpler.

 

You could just do this for OnSelect of camera control:

 

Collect(
    CameraPhotos;
    {
        Base64String: JSON(
            Camera2.Photo;
            JSONFormat.IncludeBinaryData
        );
        DisplayString: Camera2.Photo
    }
)

 

When someone takes a picture (uses OnSelect of camera control), this will add a new record in the CameraPhotos collection, with the 2 columns: Base64String and DisplayString.

 

- Base64String you can use to upload to SQL

- DisplayString you can use in an image control in your gallery, setting the Image property of the image to ThisItem.DisplayString

 

Obviously you can fill other columns as well, depening on any other metadata you want to collect for the photo

View solution in original post

4 REPLIES 4
KvB1
Solution Specialist
Solution Specialist

How are the photos collected right now?

 

You can set the Image property of an image control to Camera1.Photo, then OnSelect of the camera control 

Set(
    varJsonAttachment,
    JSON(
        (Image1.Image),
        JSONFormat.IncludeBinaryData
    )
);;

 

I'm not even sure if you need the image, maybe its sufficient to replace Image1.Image with Camera1.Photo, but I didnt test

 

You then add this variable to your collection as the Base64 string

Hi, 

 

Thanks for your suggestion. I seem to be getting a base64 string now (I put a label in to show the contents of the variable for testing). However my photos don't appear in the gallery at all. Also will the base64 string apply to all photos?

 

ITBird_0-1627035889516.png

This is my code onselect of the Take Photo button. 

Set(
    varJsonAttachment,
    JSON(
        (Image1.Image),
        JSONFormat.IncludeBinaryData
    )
);
Collect(
    CameraPhotos,
    CameraPhoto.Image
);

I have ThisItem.Photo as the image control, which is within a gallery collection CameraPhotos

 

KvB1
Solution Specialist
Solution Specialist

I'm sorry, I made a mistake. You don't need the image control in order to convert to Base64, so the solution is a lot simpler.

 

You could just do this for OnSelect of camera control:

 

Collect(
    CameraPhotos;
    {
        Base64String: JSON(
            Camera2.Photo;
            JSONFormat.IncludeBinaryData
        );
        DisplayString: Camera2.Photo
    }
)

 

When someone takes a picture (uses OnSelect of camera control), this will add a new record in the CameraPhotos collection, with the 2 columns: Base64String and DisplayString.

 

- Base64String you can use to upload to SQL

- DisplayString you can use in an image control in your gallery, setting the Image property of the image to ThisItem.DisplayString

 

Obviously you can fill other columns as well, depening on any other metadata you want to collect for the photo

View solution in original post

ITBird
New Member

Thank you so much! That has done what I need it to do 🙂

Helpful resources

Announcements
PA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

R2 (Green) 768 x 460px.png

Microsoft Dynamics 365 & Power Platform User Professionals

DynamicsCon is a FREE, 4 half-day virtual learning experience for 11,000+ Microsoft Business Application users and professionals.

Users online (1,407)