diff --git a/app/services/archive_uploader.rb b/app/services/archive_uploader.rb index 38750d211..682cd2072 100644 --- a/app/services/archive_uploader.rb +++ b/app/services/archive_uploader.rb @@ -6,7 +6,20 @@ class ArchiveUploader def upload(archive) uploaded_blob = create_and_upload_blob - archive.file.attach(uploaded_blob) + begin + archive.file.purge if archive.file.attached? + rescue ActiveStorage::FileNotFoundError + archive.file.destroy + archive.file.detach + end + archive.reload + uploaded_blob.reload + ActiveStorage::Attachment.create( + name: 'file', + record_type: 'Archive', + record_id: archive.id, + blob_id: uploaded_blob.id + ) end def blob @@ -56,7 +69,7 @@ class ArchiveUploader key: namespaced_object_key, filename: filename, content_type: 'application/zip', - metadata: { virus_scan_result: ActiveStorage::VirusScanner::SAFE } + metadata: { analyzed: true, virus_scan_result: ActiveStorage::VirusScanner::SAFE } } end