I'm encrypting my Shrine file uploads in a controller action, and need some way of validating their mime types before doing anything else. Shrine's validation plugins are great, but they do not work on encrypted files. I need to come up with a way around this.
Suggestions here are for ActiveStorage, and seem off. The first post suggests validating in the model, but I need to do it in the controller. Possibly something like...
def create
image = params.require(:id_doc).fetch(:image)
respond_to do |format|
if image.content_type == 'image/jpeg' || image.content_type == 'image/png' && image.size <= 3.megabytes
#encrypt file and save
format.html { redirect_to root_path }
else
format.html { redirect_to onboard_queued_path }
end
end
Even then it seems insecure. I could just change file names. This answer seems promising. Alternately I could use this but I would prefer not to install an entire gem.