Fix and test ActiveStorage::IntegrityError on upload

This commit is contained in:
Paul Chavard 2020-12-10 21:55:45 +01:00 committed by simon lehericey
parent 33a5d74c1e
commit fed300bfe1
2 changed files with 37 additions and 2 deletions

View file

@ -5,11 +5,14 @@ module Mutations
def validate_blob(blob_id)
begin
blob = ActiveStorage::Blob.find_signed(blob_id)
blob.identify
# open downloads the file and checks its hash
blob.open { |f| }
true
rescue ActiveStorage::FileNotFoundError
return false, { errors: ['Le fichier na pas été correctement téléversé sur le serveur de stockage'] }
rescue ActiveSupport::MessageVerifier::InvalidSignature
return false, { errors: ['Lidentifiant du fichier téléversé est invalide'] }
rescue ActiveStorage::IntegrityError
return false, { errors: ['Le hash du fichier téléversé est invalide'] }
end
end