Fix and test ActiveStorage::IntegrityError on upload
This commit is contained in:
parent
33a5d74c1e
commit
fed300bfe1
2 changed files with 37 additions and 2 deletions
|
@ -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 n’a pas été correctement téléversé sur le serveur de stockage'] }
|
||||
rescue ActiveSupport::MessageVerifier::InvalidSignature
|
||||
return false, { errors: ['L’identifiant du fichier téléversé est invalide'] }
|
||||
rescue ActiveStorage::IntegrityError
|
||||
return false, { errors: ['Le hash du fichier téléversé est invalide'] }
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue