Automatic Moderation of images in a SharePoint folder to exclude racy images from PDF Merge

In my previous blog, we used ‘Image Moderation API’ with Power Automate(Microsoft Flow) and Moderated Image from SharePoint Online list attachment.

When talking to one of our customers, about the ‘Image Content Moderator API’ he told me that his company has recently asked him to Moderate few images(100 around) and Merge the Non-Racy images into a single PDF.

With Muhimbi you can easy select the file from the User-Interface and Convert them into a single PDF but that now moderating 100 images can be very time consuming and boring. So he asked me if could automate the process using Power Automate. This is the use can for this blog.

Before we begin:

  • A Microsoft Azure account. Start a free trial or sign in.
  • Create a Content Moderator resource in the Azure portal and use the free tier.
  • The key and endpoint that was generated for you during sign-up.
  • Muhimbi PDF Converter Services Online full, free or trial subscription(Sign up).
  • Appropriate privileges to create Flows.

Now that we have our prerequisites in place let start building our Power Automate(Microsoft Flow):

Note: All the images are sample images provided my Microsoft for Testing the Content Moderator API.

I have downloaded the above file and uploaded them to a SharePoint Online folder.

Any guesses which image can be classified as Racy?

From a high level our Flow will look like the screenshot below:

Step 1: Navigate to And click on ‘Instant flow’.

  • In the Flow designer your trigger should look like the screenshot below:

Step 2: Add the SharePoint Online ‘List folder’ action and specify the folder containing the images to merge.

Step 3: Initialize a variable of type Array and Name it ‘Files’.

Step 4: Add the ‘Apply to each’ loop and set it to the ‘Body’; field, output of the SharePoint Online ‘List folder’ action.

Step 5:

  • Add the ‘Get file content using path’ SharePoint action.
  • Add the ‘Site-Address’ and create the ‘File Path’ using the ‘Name’ the output of the ‘List folder’ action.

Step 6: Add Azure Content Moderator ‘Check if an image contains racy or adult content’.

  • In the ‘Image Source’ select ‘Image Content’.
  • In the ‘Image Content’ select the ‘File Content’ the output of the SharePoint ‘Get file content using path’ action.

Step 7: Add a ‘Condition’ in Flow. Add the ‘Is Image classified as Racy’ is the output of the ‘Check if an image contains racy or adult content’ Condition’ is equal to’ ‘false’.

Step 8:

  • if(No), do nothing.
  • If(yes),
    • Add the ‘Append to variable’ action and specify the following values:
    • Name: Files
    • Value:
 "source_file_name": @{items('Apply_to_each_2')?['Name']},
 "source_file_content": @{base64(body('Get_file_content_using_path'))

Step 9: Outside the ‘Apply to each’ loop add the Merge Action, click ‘Switch to detail inputs for array item’ and pass the ‘Files’ variable (the output of the ‘Append to array’ Variable action).

Step 10:  Use the ‘Create file’ SharePoint action to store the PDF document into SharePoint document library.

  • File name: For this Demo, we will hard code the Name to  MergedImage.pdf
  • File content: Processed file content the (output variable of the ‘Merge’ )action.

Step 11: That’s it- you’re done! Select the Test button from the top of your screen. In the Test pane, select the options ‘I’ll perform the trigger action‘ for testing your flow.

After few seconds, you should have a file in the output Folder without the Racy image. Again any guesses, How many Image in the Merged PDF? The answer is three images.

In this demo we have used the power of Content Moderator Image API and skipped the Merging of Racy Images.

Subscribe to this blog for the latest updates about SharePoint Online, Microsoft Flow, Power Apps and document conversion and manipulation.

2 thoughts on “Automatic Moderation of images in a SharePoint folder to exclude racy images from PDF Merge

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s