Hello,
I’m trying to add a media file (a picture.jpg) to an existing item using the Omeka S API. The media itself is successfully added to the item, which is great. However, I’ve been struggling for two days to include metadata (like title, creator, description, etc.) for the media, and nothing seems to work — the metadata is never saved.
Here is the code I’m using (python):
import requests
import json
url = “https://omekas.test/api/media?key_identity=YDJvt5PMD1VaqB87dZ7O8C21pUsDoDPR&key_credential=BWOWBuMRkaWLlFfKoKqbc01HWrLYHJhB”
files = {
“file[0]”: (“B987352101_FCG21-3_001.jpg”, open(“jpg/B987352101_FCG21-3_001.jpg”, “rb”), “image/jpeg”)
}
data = {
“data”: json.dumps({
“o:ingester”: “upload”,
“file_index”: “0”,
“o:item”: {“o:id”: 54728},
“dcterms:title”: [{“@value”: “Titre ajoute a la creation”, “type”: “literal”}],
“dcterms:creator”: [{“@value”: “Jean-Claude Bosmel”, “type”: “literal”}],
“dcterms:spatial”: [{“@value”: “Moorea”, “type”: “literal”}],
“dcterms:description”: [{“@value”: “Description ajoutee a la creation”, “type”: “literal”}]
})
}
response = requests.post(url, files=files, data=data)
if response.status_code == 200:
print(“-- Média créé avec succès.”)
print(json.dumps(response.json(), indent=2))
else:
print(f"-- Erreur API : {response.status_code}")
print(response.text)
Could you please let me know what I might be doing wrong? Is there something I’m missing about how metadata should be structured when creating a media?
Thank you very much for your help and for all the work on Omeka S!
Best regards,
Marc