<p>From investigating, the issue could not be resolved at the time of writing this answer. Even though the <code>EVENT_BEFORE_HANDLE_FILE</code> on the Asset class extends the cancelable event, there was not actually a way to cancel.</p>
<p>To answer the question, there is currently no nice way of being able to cancel this event.</p>
<p>I raised a ticket to add this feature, you can follow its progress here <a href="https://github.com/craftcms/cms/issues/6875" rel="nofollow noreferrer">https://github.com/craftcms/cms/issues/6875</a></p>
<p>This would allow you to use <code>$event-&gt;isValid = false;</code> in the scenario any tests fail and you didn't want the image to continue being handled by Craft.</p>

CC BY-SA 4.0
2020-09-25T17:11:39.660Z
2020-09-25T17:11:39.660Z
zizther
<p>I have a frontend form where images can be uploaded.</p>
<p>I am handling the image moderation within <code>EVENT_BEFORE_HANDLE_FILE</code> on the Asset class. I am setting session errors for any moderation issues detected.</p>
<p>This is all working great, however I need a way of stopping the image uploading if errors are detected, but I want the session errors to continue to show as the page refreshes.</p>
<p>What is the best way to stop the image upload in this event, but for it to still set the session errors?</p>
<p>Thanks</p>

<image><events><modules>
Stop image upload if moderation fails using EVENT_BEFORE_HANDLE_FILE
# Stop image upload if moderation fails using EVENT_BEFORE_HANDLE_FILE

(Asked by: username_0 on 2020-09-16)

I have a frontend form where images can be uploaded.

I am handling the image moderation within `EVENT_BEFORE_HANDLE_FILE` on the Asset class. I am setting session errors for any moderation issues detected.

This is all working great, however I need a way of stopping the image uploading if errors are detected, but I want the session errors to continue to show as the page refreshes.

What is the best way to stop the image upload in this event, but for it to still set the session errors?

Thanks

**Tags:** image, events, modules

---

## 1 answers

### Answer by username_0 on 2020-09-25. Score: 1 | Accepted answer

From investigating, the issue could not be resolved at the time of writing this answer. Even though the `EVENT_BEFORE_HANDLE_FILE` on the Asset class extends the cancelable event, there was not actually a way to cancel.

To answer the question, there is currently no nice way of being able to cancel this event.

I raised a ticket to add this feature, you can follow its progress here <https://github.com/craftcms/cms/issues/6875>

This would allow you to use `$event->isValid = false;` in the scenario any tests fail and you didn't want the image to continue being handled by Craft.


---

