What you basically need to do is using the ResourceManager to import a new Resource object from a file or content.
So, let’s assume you have a file somewhere which contains the CSV data, then you inject the ResourceManager as a property of your class (probably a controller) and then do:
Now you have a (persisted) Resource object, but you probably want to attach it to some other object (a domain model) in order to find it again, for example a Backup model:
$backup = new Backup;
$backup->setResource($resource);
$this->backupRepository->add($backup);
If you don’t have a CSV file but generated the data in memory, you can simply import the resource from content:
thanks for getting back to me on this. I moved on, hence my late reply, and decided to use a model object to persist the data and update the data for now in the db. But I will come back to this and see if I can get it to work.
From what you have said I think I understand that if I connect the persistent resource to a model object I can reload it update it and save it again?
upload a new file, which results in a brand new resource object
detach the old resource object from the model
attach (add) the new resource object to the model
make sure to persist the updated mode by calling update() on its repository
Flow will clean up all unused resource data and make sure to unpublish resources (even from a CDN) when they are not referenced by any resource object any more.