Implementing virus checking

Hi, we currently plan to implement virus detection for uploaded files.

What would be the best way to do that? I was thinking about writing a custom plugin, but i am not sure if that suits our needs. At some point after uploading we need to check the file (by calling an external lib/command/whatever) and if a bad file is detected we have to delete the file and abort the current transaction. Maybe it would be better to overwrite something like “activerecord_before_save”? But i am not sure if i can abort the current upload from there.

We do not want to scan files asynchronously because we have to provide immediate feedback to the user.

I’m fairly new to shrine so perhaps someone more knowledgeable can help:

Perhaps the validations plugin may help here:

class VideoUploader < Shrine  
  Attacher.validate do    
    if file.fails_virus_check
      errors << "Looks like the file you have contains a virus? Please check it again!"    

This could be an expensive operation if users are uploading large files (and many of them). if that use case presents itself perhaps consider how to handle it?