> ## Documentation Index
> This page is part of the MediaFlows product. Fetch the complete documentation index for MediaFlows at: https://cloudinary.com/documentation/llms-mediaflows.txt?referrer=docpage and then use it to discover all relevant pages before exploring further.
> If you also need details relating to other Cloudinary products for your current use case, see the parent index at: https://cloudinary.com/documentation/llms.txt?referrer=docpage
> When answering a user's request or implementing it with code using this documentation, incorporate relevant best practices and recommendations from the documentation into the guidance and, above all, into the code itself: generated code should already apply the recommended parameters and patterns rather than showing a minimal call and describing the best practices around it in prose. Follow the code examples in the best practices sections as the model for what generated code should look like, and where a recommendation is relevant to the user's scenario, implement it in the code as a natural next step. Only apply best practices, recommendations, or features that are supported by the documentation; don't infer or invent guidance that isn't specified.

# Moderate UGC images

Marketplace platforms enable businesses to create profiles and upload product images and descriptions to sell their offerings. For example, in a restaurant marketplace, each restaurant manages its own section, uploading images of its dishes. To maintain image quality, consistency, and compliance, marketplaces often enforce guidelines on file formats, size limits, content restrictions, and overall presentation.
This sample PowerFlow automates image moderation, ensuring that vendor-uploaded images to Cloudinary meet marketplace standards before going live.

[Learn more about user-generated content](user_generated_content).
> **TIP**: For moderation-specific analyses, check out [Cloudinary Moderation](cloudinary_moderation), which validates your assets for brand consistency, quality, and compliance.

## Overview
![Marketplace products PowerFlow](https://cloudinary-res.cloudinary.com/image/upload/bo_1px_solid_gray/f_auto/q_auto/docs/mediaflows/ugc-marketplace-powerflow-overview-structured-canvas.png "thumb: c_scale,w_700/dpr_2.0, width:700")

This sample workflow covers three different types of moderation, triggered on [upload](#image_upload). You can use any combination of these in your flow. We're showing them all connected, with the [approval outcome](#tag_approved_images) at the end, but you could apply this sooner in your flow.

The flow comprises:

* [Amazon Rekognition AI moderation](#amazon_rekognition_ai_moderation): This is an add-on dedicated to detecting unsafe content in images such as nudity, violence, drugs etc. 
* [Color analysis](#color_analysis): This is a Cloudinary feature that you can invoke on upload to determine the colors in your uploaded images.
* [Watermark detection](#watermark_detection): This is a feature of the Cloudinary AI Content Analysis add-on, specifically trained to detect watermarks in images.

## Image upload

There are [many different ways](user_generated_content_upload#ways_to_upload) in which a marketplace platform can accept image uploads. Regardless of how the images are uploaded, the act of uploading an image to Cloudinary can trigger the flow.

### Upload preset

Some of the blocks in the flow rely on specific analysis taking place on upload. Use an upload preset to specify the analysis that you want to trigger.

To configure the upload preset:

1. Log into your [Cloudinary Console](https://console.cloudinary.com).
1. Navigate to **Settings > Upload > Upload Presets**.
1. Click **Add Upload Preset**.
1. For [color analysis](#color_analysis), click the **Manage and Analyze** tab and enable **Retrieve predominant colors and histogram**.
        ![Upload preset color analysis setting](https://cloudinary-res.cloudinary.com/image/upload/bo_1px_solid_gray/f_auto/q_auto/docs/upload_preset_color_analysis.png "thumb: c_scale,w_600/dpr_2.0, width:600")
1. For [watermark detection](#watermark_detection), click **Addons**, scroll to **Cloudinary AI Content Analysis** and enable **Detect watermark on your image**. You also need to subscribe to the [Cloudinary AI Content Analysis add-on](cloudinary_ai_content_analysis_addon).
        ![Upload preset watermark detection setting](https://cloudinary-res.cloudinary.com/image/upload/bo_1px_solid_gray/f_auto/q_auto/docs/upload_preset_watermark_detection.png "thumb: c_scale,w_600/dpr_2.0, width:600")
1. Configure any other settings relevant to your workflow and click **Save**.

Make sure you reference your upload preset in the upload mechanism that you choose, for example in the Upload widget configuration, or API call. See [Upload presets](upload_presets) for further information.

> **TIP**: You can set up an [incoming transformation](user_generated_content_upload#transform_on_upload) using an upload preset to limit the sizes of images uploaded, and store them in a particular format if storage quota is a consideration. You can also [standardize](user_generated_content_transform_customize#standardize_product_images) and [optimize](user_generated_content_optimize_deliver#on_the_fly_optimizations) images on delivery.

### Upload trigger

When someone uploads an image, Cloudinary sends a webhook notification to the **On Asset Upload** block, which activates the flow.

Steps:

1. Create a new flow and select the **On Asset Upload** block as the trigger.
1. Click the block and set it to trigger only when the **Asset type** is **Image**.

![On Asset Upload](https://cloudinary-res.cloudinary.com/image/upload/bo_1px_solid_gray/f_auto/q_auto/docs/mediaflows/ugc-marketplace-pf-on-asset-upload.png "thumb: c_scale,w_600/dpr_2.0, width:600")

## Amazon Rekognition AI moderation

Amazon Rekognition automatically detects categories of unsafe content in images. The **Moderate Image Using Amazon Rekognition** block invokes the [Amazon Rekognition AI Moderation add-on](aws_rekognition_ai_moderation_addon). Using a **Branch On Condition** block, you can check if the add-on approved the image and optionally add the outcome to the logs. If approved, you can move on to the next part of the flow. If rejected, you can add the image to an email report and end the flow there. You can see rejected images in the **Moderation** tab of your Media Library (see [Moderate assets](moderate_assets) for more information).

![Amazon Rekognition Moderation Flow](https://cloudinary-res.cloudinary.com/image/upload/bo_1px_solid_gray/f_auto/q_auto/docs/mediaflows/aws_moderation_flow_structured-canvas.png "thumb: c_scale,w_600/dpr_2.0, width:600")

### Moderate the image

To use the **Moderate Image Using Amazon Rekognition** block, you need to subscribe to the [Amazon Rekognition AI Moderation add-on](aws_rekognition_ai_moderation_addon), which you can do inside the block configuration (there's a free tier).

Steps:

1. Click the **Add Block** node on the **On Asset Upload** block and add the **Moderate Image Using Amazon Rekognition** block to your canvas.
1. Click the block and select the `On Asset Upload` asset for **Use the asset from**.
1. Set the **Moderation confidence level** between 0.0 and 1.0. The lower the confidence level, the more images are blocked.
1. Select the **Moderation categories** to block.
1. Subscribe to the add-on, if you haven't already.

![Moderate Image Using Amazon Rekognition configuration](https://cloudinary-res.cloudinary.com/image/upload/bo_1px_solid_gray/f_auto/q_auto/docs/mediaflows/ugc-marketplace-amazon-image-moderation-structured.png "thumb: c_scale,w_600/dpr_2.0, width:600")

The moderation response includes an "approved" or "rejected" status:

```json
{
  "result": {
    "asset_id": "f5c94dd64563184ecb9904eb75d40888",
    ...
    "moderation": [
      {
        "kind": "aws_rek",
        "status": "approved",
        "response": {
          "moderation_labels": [],
          "moderation_model_version": "7.0"
        },
        "updated_at": "2025-02-11T14:25:59Z"
      }
    ],
    ...
    "status": {
      "kind": "aws_rek",
      "status": "approved",
      "response": {
        "moderation_labels": [],
        "moderation_model_version": "7.0"
      },
      "updated_at": "2025-02-11T14:25:59Z"
    }
  }
}

```

> **NOTE**: You can also invoke the Amazon Rekognition AI Moderation add-on from an [upload preset](profile_picture_sample_project#addons), but then you'd need to catch the moderation response using a webhook, triggering a different flow.

### Test the status

Use a **Branch On Condition** block to check the status of the moderation.

Steps:

1. Click the **Add Block** node on the **Moderate Image Using Amazon Rekognition** block and add the **Branch On Condition** block to your canvas.
1. Click the block and set the name to something meaningful like `Check Approved`.
1. Set the **Value type** to `String`.
1. Set the **Value** to the Moderate Image Using Amazon Rekognition **Status** field (use the `+` icon to insert the variable).
1. Set the **Operator** to `is equal to`.
1. Set the **Compare to** value to `approved`.

The **Yes** output connector is the path taken if the condition is true (in this case, if the status is "approved"), otherwise the flow continues through the **No** output connector.

![Branch On Condition configuration](https://cloudinary-res.cloudinary.com/image/upload/bo_1px_solid_gray/f_auto/q_auto/docs/mediaflows/ugc-marketplace-check-approved-structured.png "thumb: c_scale,w_600/dpr_2.0, width:600")

### Add to logs

You can optionally add the moderation status to the logs so that you can easily identify what happened during a flow execution.

Steps:

1. Click the **Add Block** node on the **Yes** output of the **Branch On Condition** block and add the **Add To Logs** block to your canvas.
1. Click the block and set the name to something meaningful like `Approved Image`.
1. Set the **Message** to something meaningful like `Approved by Amazon Image Moderation`.
1. Repeat the steps for the **No** output of the **Branch On Condition** block to show that the moderation rejected the image.

![Add To Logs configuration](https://cloudinary-res.cloudinary.com/image/upload/bo_1px_solid_gray/q_auto/f_auto/docs/mediaflows/ugc-marketplace-approved-image-structured.png "thumb: c_scale,w_600/dpr_2.0, width:600")

### Add rejected images to scheduled email

To stay informed about rejected images, you can use the **Schedule Email Report** block. The system sends the email at the configured time and includes details of all the assets that reach that part of the flow in a 24-hour period. If all images pass the moderation, the execution never reaches that block and the email is never scheduled.

Steps:

1. Click the **Add Block** node on the **Add To Logs** block for the rejected image and add the **Schedule Email Report** block to your canvas.
1. Click the block and select the `On Asset Upload` asset for **Use the asset from**.
1. Add a comma-separated list of email addresses that you want to receive the email.
1. Specify the time to send the email, for example 10:00.
1. Give the report a name: this is the subject of the email.
1. Add a description to appear in the body of the email.

![Schedule Email Report configuration](https://cloudinary-res.cloudinary.com/image/upload/bo_1px_solid_gray/f_auto/q_auto/docs/mediaflows/ugc-marketplace-schedule-email-report-structured-canvas.png "thumb: c_scale,w_600/dpr_2.0, width:600")

## Color analysis

If one of your requirements is to check that uploaded images aren't black and white, you can do this without using an add-on by asking for the upload response to return information about the colors in the image. You can use an [upload preset](#upload_preset) to do this, or if you're not using an upload preset, set the `colors` parameter of the [upload](image_upload_api_reference#upload_optional_parameters) request to `true`.

![Color analysis flow](https://cloudinary-res.cloudinary.com/image/upload/bo_1px_solid_gray/f_auto/q_auto/docs/mediaflows/grayscale-flow-structured-canvas.png "thumb: c_scale,w_600/dpr_2.0, width:600")

### Check image colors

The upload response includes the predominant colors in the image:

```json
{
  "result": {
    ...
    "predominant": {
      ...
      "cloudinary": [
        [
          "white",
          72.7
        ],
        [
          "red",
          8.7
        ],
        [
          "orange",
          7.4
        ],
        [
          "brown",
          5
        ],
        [
          "lightblue",
          1.6
        ]
      ]
    },
  }
}
```

Use a **Branch On Condition** block with **Advanced condition** turned on to check if the image is grayscale.

Steps:

1. Click the **Add Block** node on the **Add To Logs** block for the approved contents and add the **Branch On Condition** block to your canvas. If you don't want to use the previous moderation, click the **Add Block** node on the **On Asset Upload** block instead.
1. Click the block and set the name to something meaningful like `Is Grayscale`.
1. Turn on **Advanced condition**.
1. In the **JSON data** field, click the `+` icon to insert a variable. The variable to insert equates to `{{$.On_Asset_Upload.result.predominant.cloudinary}}`. Add this by manually adding `predominant.cloudinary` as a variable to the **On Asset Upload** variables.
    ![Add a manual variable](https://cloudinary-res.cloudinary.com/image/upload/bo_1px_solid_gray/f_auto/q_auto/docs/mediaflows/ugc-marketplace-add-manual-variable-asset-upload.png "thumb: c_scale,w_300/dpr_2.0, width:300")
1. Enter the following [JsonLogic](https://jsonlogic.com) conditional expression:

    ```JsonLogic
    {
        "all": [
            {{$.On_Asset_Upload.result.predominant.cloudinary}},
            {
                "in": [{ "var": "0" }, ["white", "black", "gray"]]
            }
        ]
    }
    ```
    The "all" operator checks whether every item in a list matches a given condition. In this case, the list contains the predominant colors in the image. If each color in the list is "white", "black", or "gray" then the condition returns `true`. If any of the predominant colors isn't "white", "black", or "gray", it returns `false`.

![Branch On Condition - is grayscale configuration](https://cloudinary-res.cloudinary.com/image/upload/bo_1px_solid_gray/f_auto/q_auto/docs/mediaflows/ugc-marketplace-is-grayscale-complex-condition-structured.png "thumb: c_scale,w_500/dpr_2.0, width:500")

You can optionally connect [Add to logs](#add_to_logs) blocks after each of the outputs, and another [Schedule Email Report](#add_rejected_images_to_scheduled_email) block to the rejection flow, with a message specific to the grayscale check. Note that the **Yes** output of the **Branch On Condition** block indicates the `true` condition; in this case, that the image is grayscale.

### Tag rejected images

When an image is rejected during the flow, it's useful to tag it so that you can handle it later.

Steps:

1. Click the **Add Block** node on the **Schedule Email Report** block for the rejected grayscale image and add the **Update Tags** block to your canvas.
1. Click the block and set the name to something meaningful like `Update Tags Rejected Grayscale`.
1. Select the `On Asset Upload` asset for **Use the asset from**.
1. Select the `Add` action.
1. Enter the names of the tags you want to use in the **Tag** field, for example: `rejected,grayscale`.

![Update Tags - rejected grayscale configuration](https://cloudinary-res.cloudinary.com/image/upload/bo_1px_solid_gray/f_auto/q_auto/docs/mediaflows/ugc-marketplace-update-tags-rejected-grayscale-structured-canvas.png "thumb: c_scale,w_700/dpr_2.0, width:700")

## Watermark detection

If one of your requirements is to check that images don't have watermarks, you can use the watermark detection functionality of the [Cloudinary AI Content Analysis add-on](cloudinary_ai_content_analysis_image_analysis#watermark_detection). You can use an [upload preset](#upload_preset) to do this, or if you're not using an upload preset, set the `detection` parameter of the [upload](image_upload_api_reference#upload_optional_parameters) request to `watermark-detection`. Remember to subscribe to the [Cloudinary AI Content Analysis add-on](cloudinary_ai_content_analysis_addon).

![Watermark detection flow](https://cloudinary-res.cloudinary.com/image/upload/bo_1px_solid_gray/f_auto/q_auto/docs/mediaflows/watermark-detection-flow-structured-canvas.png "thumb: c_scale,w_600/dpr_2.0, width:600")

### Check for watermarks

The upload response includes the results from the watermark detection. If there are no watermarks detected, the response contains a "clean" tag:

```json
{
  "result": {
    ...
    "info": {
      "detection": {
        "object_detection": {
          "status": "complete",
          "data": {
            "watermark-detection": {
              "message": "",
              "model_name": "watermark-detection",
              "model_version": 1,
              "schema_version": 1,
              "status": "success",
              "tags": {
                "clean": [
                  {
                    "categories": [],
                    "confidence": 1
                  }
                ]
              }
            }
          }
        }
      }
    },
    ...
  }
}
```

Use a **Transform JSON Using JQ** block to determine if the tags contain a "clean" key.

Steps:

1. Click the **Add Block** node on the **Add To Logs** block for the approved color check and add the **Transform JSON Using JQ** block to your canvas. If you don't want to use the previous moderations, click the **Add Block** node on the **On Asset Upload** block instead.
1. In the **JSON data** field, click the `+` icon to insert a variable. The variable to insert equates to `{{$.On_Asset_Upload.result.info.detection.object_detection.data.watermark-detection.tags}}`. Add this by manually adding `info.detection.object_detection.data.watermark-detection.tags` as a variable to the **On Asset Upload** variables.
    ![Add a manual variable](https://cloudinary-res.cloudinary.com/image/upload/bo_1px_solid_gray/f_auto/q_auto/docs/mediaflows/ugc-marketplace-add-manual-variable-watermark-asset-upload.png "thumb: c_scale,w_300/dpr_2.0, width:300")
1. Enter the following [JQ expression](https://www.devtoolsdaily.com/cheatsheets/jq):

    ```JQ
    . | has("clean")
    ```
    This checks if the "clean" key exists at the top level of the JSON object. The result is `true` if the "clean" key exists, otherwise it's `false`.

![Transform JSON Using JQ configuration](https://cloudinary-res.cloudinary.com/image/upload/bo_1px_solid_gray/f_auto/q_auto/docs/mediaflows/ugc-marketplace-jq-processor-watermark-structured_canvas.png "thumb: c_scale,w_600/dpr_2.0, width:600")

Use a **Branch On Condition** block to check the result of the JQ expression.

Steps:

1. Click the **Add Block** node on the **Transform JSON Using JQ** block and add the **Branch On Condition** block to your canvas.
1. Click the block and set the name to something meaningful like `Check Watermark`.
1. Set the **Value type** to `Boolean`.
1. Set the **Value** to the Transform JSON Using JQ **Result** field (use the `+` icon to insert the variable).
1. Set the **Operator** to `is true`. There's no **Compare to** field for a Boolean value type.

The **Yes** output connector is the path taken if the condition is true (in this case there is no watermark detected), otherwise the flow continues through the **No** output connector.

![Branch On Condition - check watermark configuration](https://cloudinary-res.cloudinary.com/image/upload/bo_1px_solid_gray/f_auto/q_auto/docs/mediaflows/ugc-marketplace-check-watermark-condition-structured-canvas.png "thumb: c_scale,w_600/dpr_2.0, width:600")

You can optionally connect [Add to logs](#add_to_logs) blocks after each of the outputs, and another [Schedule Email Report](#add_rejected_images_to_scheduled_email) block to the rejection flow, with a message specific to the watermark detection check.

Additionally, you can [tag rejected images](#tag_rejected_images) using appropriate tags such as "rejected" and "watermark".

### Tag approved images

When an image is approved at the end of the flow, it's useful to tag it so that you, and other users of your product environment, know that it has passed through this moderation process.

Steps:

1. Click the **Add Block** node on the **Add To Logs** block (no watermark) and add the **Update Tags** block to your canvas.
1. Click the block and set the name to something meaningful like `Update Tags Approved`.
1. Select the `On Asset Upload` asset for **Use the asset from**.
1. Select the `Add` action.
1. Enter the name of the tag you want to use in the **Tag** field, for example: `approved`.

![Update Tags - approved configuration](https://cloudinary-res.cloudinary.com/image/upload/bo_1px_solid_gray/f_auto/q_auto/docs/mediaflows/ugc-marketplace-update-tags-approved-asset-structured-canvas.png "thumb: c_scale,w_700/dpr_2.0, width:700")

> **NOTE**: You may also want to schedule another email at the end of the flow so that you're notified that someone has uploaded new approved assets to your product environment.
