Import media and replace files

I’m using the CSVImport module from Omeka S in order to import pictures of paintings that are getting associated with a notice of the painting.

Sometime, we have a better picture of the painting and we want to replace the previous picture by the new one. Unfortunately, it seems that CSVImport module is not keeping the original name of the jpeg file and is renaming it using something like a unique hash. This allow to have more that one file associated with a notice where I would like the second one to replace the first one.

How could that be possible?

Depending on how many files you want to update at a time, this may be easier to do manually than with CSV Import.

If you have the item IDs (or another unique value) already in your spreadsheet, you can do this in a two-stage process. This will delete every media attached to the given items, not any one file in particular, so this may not work for you.

First, run a CSV Import where you “Update” the items. Supply only one mapped column: an empty column, mapped to Media source > URL.

When CSV Import updates the items, it will wipe any existing media (and replace it with nothing). This shouldn’t mess up any metadata, item sets, sites, etc., but test it with a few items first to be sure you have it right. Then you can wipe all media from the items you intend to update.

Then you can run CSV Import as usual by adding the new media to the existing items.

If you have items with more than one media (photos of the back, details, etc.), and you want to delete only one image in order to replace it, that’s probably a manual job. Keep in mind that media are assigned unique IDs, just like items, starting with 1, so the older the media, the lower the number. You can change the columns that appear on the Media browsing page to show IDs and then sort using them, if that helps you search out the files you wish to delete.

Thank you @AllanaMayer for your answer. It took me some time to try your solution as you answered me in march and I only tried it tonight. I get an error while trying your way of deleting media. Here is the error from the log:

2023-09-18T22:59:24+00:00 ERR (3): Doctrine\ORM\ORMInvalidArgumentException: A new entity was found through the relationship 'Omeka\Entity\Item#primaryMedia' that was not configured to cascade persist operations for entity: DoctrineProxies\__CG__\Omeka\Entity\Media@3472. To solve this issue: Either explicitly call EntityManager#persist() on this unknown entity or configure cascade persist this association in the mapping for example @ManyToOne(..,cascade={"persist"}). If you cannot find out which entity causes the problem implement 'Omeka\Entity\Media#__toString()' to get a clue. in /srv/data/web/vhosts/htdocs/vendor/doctrine/orm/lib/Doctrine/ORM/ORMInvalidArgumentException.php:97
Stack trace:
#0 /srv/data/web/vhosts/htdocs/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php(3521): Doctrine\ORM\ORMInvalidArgumentException::newEntitiesFoundThroughRelationships()
#1 /srv/data/web/vhosts/htdocs/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php(390): Doctrine\ORM\UnitOfWork->assertThatThereAreNoUnintentionallyNonPersistedAssociations()
#2 /srv/data/web/vhosts/htdocs/vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php(392): Doctrine\ORM\UnitOfWork->commit()
#3 /srv/data/web/vhosts/htdocs/application/src/Api/Adapter/AbstractEntityAdapter.php(447): Doctrine\ORM\EntityManager->flush()
#4 /srv/data/web/vhosts/htdocs/application/src/Api/Manager.php(233): Omeka\Api\Adapter\AbstractEntityAdapter->update()
#5 /srv/data/web/vhosts/htdocs/application/src/Api/Manager.php(136): Omeka\Api\Manager->execute()
#6 /srv/data/web/vhosts/htdocs/modules/CSVImport/src/Job/Import.php(809): Omeka\Api\Manager->update()
#7 /srv/data/web/vhosts/htdocs/modules/CSVImport/src/Job/Import.php(432): CSVImport\Job\Import->updateRevise()
#8 /srv/data/web/vhosts/htdocs/modules/CSVImport/src/Job/Import.php(301): CSVImport\Job\Import->update()
#9 /srv/data/web/vhosts/htdocs/modules/CSVImport/src/Job/Import.php(199): CSVImport\Job\Import->processBatchData()
#10 /srv/data/web/vhosts/htdocs/application/src/Job/DispatchStrategy/Synchronous.php(34): CSVImport\Job\Import->perform()
#11 /srv/data/web/vhosts/htdocs/application/src/Job/Dispatcher.php(105): Omeka\Job\DispatchStrategy\Synchronous->send()
#12 /srv/data/web/vhosts/htdocs/application/data/scripts/perform-job.php(66): Omeka\Job\Dispatcher->send()
#13 {main}

Do you have an idea on what can cause this error?

And it appears that the update fails completly, as I can read the following in the log:

2023-09-18T23:18:15+00:00 NOTICE (5): None of the 20 items were updated (update).

It looks like the ORM of Omeka S was not configured to modify the media attachements while updating the iem object.

I’ve just tried using the method I recommended before, and it worked fine.

Here are all the settings I used:

A reminder that the spreadsheet is listing item IDs, not media IDs, because you’re wiping all media attached to the specified items, no matter how many. By “updating” you’re erasing all existing information in that “field”, and replacing it with nothing.

I admit I am not an expert at reading error messages so that may be something more basic. Does CSV Import usually work on this installation of yours? If this doesn’t work, can you test it by creating a few simple items and let me know how that goes?