Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Apps - Building Power Apps
Unanswered

Edit Multiple Images In a Single Patch Updating SQL Server and Azure Blob Storage

(1) ShareShare
ReportReport
Posted on by 33

Hello PA Community,

 

I have an app that has two AddMediaWithImage controls and when selecting the Submit button trigger the patch which write those images to Blob Storage and their metadata to the same record in SQL Server. 

 

The new record can be edited in the app and each image can be changed individually from the form, with the changes sent in one patch, which in turn would delete its existing image in blob storage, write the new image to blob storage and then update the existing SQL record with the new meta data from the new images in blob storage.

 

The issue I've been having is on the edit side of the equation.  I can edit each image individually and patch the individual change without issue, but if I change both images and then patch, Image1 is fine, the old Image2 gets deleted in blob storage, but new Image 2 does not get written in blob storage, so new Image 2 meta data does not get updated in SQL server creating an error message on read.

 

If I reverse the code in my patch, putting Image 2 code before Image 1 code, the exact reverse happens, and Image 2 gets updated, but Image 1 does not.

 

Below is a copy of my code, I welcome any feedback you may have on resolving this issue of editing both Image under a single patch to blob storage and SQL server:

 

//Edit Record-SQL

If(

    Form1.Mode = FormMode.Edit,

   

        Patch(

            TestBlobStorage,

            LookUp(TestBlobStorage, ID = Gallery1.Selected.ID),

            {

                Test_Field:DataCardValue3.Text

            }

        )

       

);

 

//Edit Record-Image 1

If(

    Form1.Mode=FormMode.Edit,

    Set(varBlobID1, LookUp(TestBlobStorage, ID = Gallery1.Selected.ID, ImageAzureFileID1))

);

If(

    Form1.Mode=FormMode.Edit And Not(IsBlank(AddMediaButton1.Media)),

    AzureBlobStorage.DeleteFileV2("xxxxxxx", varBlobID1)

);

If(

    Form1.Mode<>FormMode.View And Not(IsBlank(AddMediaButton1.Media)),

    Set(varImage1FileName, Concatenate("TestImage", "-", Text(Now(), "yyyymmdd-HHmmss"), "-", AddMediaButton1.FileName))

);

If(

    Form1.Mode<>FormMode.View And Not(IsBlank(AddMediaButton1.Media)),

    Set(varAzureImage1, AzureBlobStorage.CreateFileV2("xxxxxxx", "xxxxxxx", varImage1FileName, AddMediaButton1.Media))

);

If(

    Form1.Mode<>FormMode.View And Not(IsBlank(AddMediaButton1.Media)),

    Collect(colImages1, {FN1: varImage1FileName, FL1: "https://xxxxxxxxxxxx.blob.core.windows.net" & varAzureImage1.Path, FID1: varAzureImage1.Id})

    );

If(

    Form1.Mode=FormMode.Edit And Not(IsBlank(AddMediaButton1.Media)),

    ForAll(

    colImages1,    

    Patch(    

        TestBlobStorage,  

        LookUp(TestBlobStorage, ID = Gallery1.Selected.ID),

            {

                ImageAzureFileName1:FN1,  

                ImageAzureFileLink1:FL1,  

                ImageAzureFileID1:FID1                

            }

        )

    )

);

 

//Edit Record-Image 2

If(

    Form1.Mode=FormMode.Edit,

    Set(varBlobID2, LookUp(TestBlobStorage, ID = Gallery1.Selected.ID, ImageAzureFileID2))

);

If(

    Form1.Mode=FormMode.Edit And Not(IsBlank(AddMediaButton1_1.Media)),

    AzureBlobStorage.DeleteFileV2("xxxxxxxx", varBlobID2)

);

If(

    Form1.Mode<>FormMode.View And Not(IsBlank(AddMediaButton1_1.Media)),

    Set(varImage2FileName, Concatenate("TestImage", "-", Text(Now(), "yyyymmdd-HHmmss"), "-", AddMediaButton1_1.FileName))

);

If(

    Form1.Mode<>FormMode.View And Not(IsBlank(AddMediaButton1_1.Media)),

    Set(varAzureImage2, AzureBlobStorage.CreateFileV2("xxxxxxx","xxxxxxx", varImage2FileName, AddMediaButton1_1.Media))

);

If(

    Form1.Mode<>FormMode.View And Not(IsBlank(AddMediaButton1_1.Media)),

    Collect(colImages2, {FN2: varImage2FileName, FL2: "https://xxxxxxxxx.blob.core.windows.net" & varAzureImage2.Path, FID2: varAzureImage2.Id})

    );

If(

    Form1.Mode=FormMode.Edit And Not(IsBlank(AddMediaButton1_1.Media)),

    ForAll(

    colImages2,    

    Patch(    

        TestBlobStorage,  

        LookUp(TestBlobStorage, ID = Gallery1.Selected.ID),

            {

                ImageAzureFileName2:FN2,  

                ImageAzureFileLink2:FL2,  

                ImageAzureFileID2:FID2                

            }

        )

    )

);

 

//New Record-SQL

If(

    Form1.Mode = FormMode.New,

        Set(

            varNewRecord,

        Patch(

                TestBlobStorage,

                Defaults

                (TestBlobStorage),

                    {

                        TimeaDate:Now(),

                        Date:DataCardValue4.Text,

                        Name:DataCardValue2.Text,  

                        Test_Field:DataCardValue3.Text

                               

                    }

            )

        )

        );

       

//New Record-Image 1

If(

    Form1.Mode=FormMode.New And Not(IsBlank(AddMediaButton1.Media)),

    ForAll(

    colImages1,    

    Patch(    

        TestBlobStorage,  

        LookUp(TestBlobStorage, ID = varNewRecord.ID),

            {

                ImageAzureFileName1:FN1,  

                ImageAzureFileLink1:FL1,  

                ImageAzureFileID1:FID1                

            }

        )

    )

);

 

//New Record-Image 2

If(

    Form1.Mode=FormMode.New And Not(IsBlank(AddMediaButton1_1.Media)),

    ForAll(

    colImages2,    

    Patch(    

        TestBlobStorage,  

        LookUp(TestBlobStorage, ID = varNewRecord.ID),

            {

                ImageAzureFileName2:FN2,  

                ImageAzureFileLink2:FL2,  

                ImageAzureFileID2:FID2                

            }

        )

    )

);

 

Notify("Form Data Submitted Successfully",NotificationType.Success);

ResetForm(Form1);

Navigate(HomeGalScreen);

 

//Clear variables and collections

Set(varNewRecord, Blank());

Set(varBlobID1, Blank());

Set(varImage1FileName, Blank());

Set(varAzureImage1, Blank());

Clear(colImages1);

Set(varBlobID2, Blank());

Set(varImage2FileName, Blank());

Set(varAzureImage2, Blank());

Clear(colImages2);

 

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

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

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,524 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 65,906 Most Valuable Professional

Leaderboard