Requirement
We have to upload images from Powerapps Canvas App in Bulk and need to store those images in Dataverse. It could be used by Field Technician to capture the device images or HR to capture Employees academic files.
Implementation
I have created a new Image Column in Dataverse and one Text field to store the ID (ID is optional). I have created a new screen in Powerapps where I added Picture control, Label, Text Input, Two buttons as shown below.
User will upload image and they will click on Add To Collection. Once all images are uploaded they will finally click on Patch To Dataverse to store those images in Dataverse.
I have written below code on Select of 'Add To Collection' button,
Collect(MyPhotos,{RecordId:TextInput1.Text, Image:UploadedImage1.Image});
Reset(TextInput1);
Reset(AddMediaButton1);
First I am collecting image and Record Id in a collection, then I am resetting both the control.
Then I have written below code on Select of 'Patch To Dataverse' button,
ForAll(MyPhotos,Patch(Employees,Defaults(Employees),{'Record ID':Value(ThisRecord.RecordId), Image:ThisRecord.Image, 'Employee Number':ThisRecord.RecordId}));
Clear(MyPhotos);
Refresh(Employees);
In this code, I am looping through each row in the collection and patching it to dataverse. Then I am removing records from the collection and refreshing the Datasource to show the latest data in Gallery.
Hope this helps!