You've encountered a common issue with the dataUriToBinary
function when working with images from Power Apps in Power Automate: the image data isn't being passed in the expected Data URI format.
Here's a breakdown of the problem and how to fix it:
Understanding the Problem:
JSON(Image1.Image, JSONFormat.IncludeBinaryData)
:
- This part of your Power Apps code converts the image data into a JSON string that includes the binary data.
- However, this JSON string is not directly compatible with the
dataUriToBinary
function in Power Automate.
dataUriToBinary
Expectation:
- The
dataUriToBinary
function in Power Automate expects the image data to be in a Data URI format, which looks something like: data:image/jpeg;base64,...
.
- The JSON string you're sending doesn't have this format.
Solution:
You need to modify your Power Apps code to extract the base64 encoded image data from the JSON string and format it as a Data URI before sending it to Power Automate.
Modified Power Apps Code:
If(
!IsBlank(SKUInput.Text),
NewStockPhotos.Run(
SKUInput.Text & ".jpg", // File name
"data:image/jpeg;base64," & Mid( // Create Data URI
JSON(Image1.Image, JSONFormat.IncludeBinaryData), // Get JSON
Find(",", JSON(Image1.Image, JSONFormat.IncludeBinaryData)) + 1 // Find base64 data
)
),
Notify("Please enter a SKU.", NotificationType.Error)
)
Explanation of Changes:
JSON(Image1.Image, JSONFormat.IncludeBinaryData)
:
- This remains the same, getting the JSON representation of the image.
Find(",", ...)
:
- This finds the position of the comma (
,
) in the JSON string, which separates the metadata from the base64 encoded image data.
Mid(..., Find(",", ...) + 1)
:
- This extracts the base64 encoded image data from the JSON string, starting after the comma.
"data:image/jpeg;base64," & ...
:
- This prepends the Data URI header (
data:image/jpeg;base64,
) to the extracted base64 data, creating the correct format for dataUriToBinary
.
- If your images are not jpeg, then change the "jpeg" portion of the string to the correct file extension.
Power Automate Flow:
You should be able to use the Power Automate template as it is, as long as the data is sent in the correct format.
Troubleshooting Tips:
- Image Format: Ensure that your camera control is capturing images in a format that Power Automate can handle (e.g., JPEG, PNG).
- Large Images: Very large images might cause issues. Try capturing smaller images to test.
- Power Automate Run History: Check the run history of your Power Automate flow for detailed error messages.
- Testing: Use the Power Apps monitor tool to check the value of the image data being sent to Power Automate.
By making these changes, your Power Apps should send the image data to Power Automate in the correct Data URI format, and the dataUriToBinary
function should work correctly.
If my answer was helpful, please click Like, and if it solved your problem, please mark it as verified to help other community members find more. If you have further questions, please feel free to contact me.
My response was crafted with AI assistance and tailored to provide detailed and actionable guidance for your Microsoft Dynamics 365 query.