Using Rails ActiveStorage causes Integrity Error when trying to analyse
I have a lot of files already on Backblaze B2 (S3 compatible) that I wish to use with ActiveStorage. The problem is, the majority of my sites data gets populated and updated by wiping it all out and being reimported by way of an Excel document and an import script.
Basically for this app, the truth is in a spreadsheet, I KNOW it's not ideal but that's the way it is here for this app.
I do not wish to download all my files each time I do a reimport.
Therefore I am writing a rake task that creates the appropriate ActiveStorage records and associates them with the correct model instances after an import. This MOSTLY works fine. It does create everything but it then comes to analysing and it says with ActiveStorage::IntegrityError. I'm not 100% sure but I assume this is something to do with the checksum?
Currently my task can be viewed here: https://gist.github.com/rctneil/7e275e74c66dd7a6ffc804ff1d740121
Any suggestions to how I can get the analysing done and the Integrity Error to be resolved?
Thanks!