Using File Sideload via REST API

Is it possible to use the File Sideload module via the REST API?

I’ve been uploading direct via the API by using /media with a POST request to create the media, with o:ingester set to “upload” and a file_index value of 0 to link to the file content passed as the file[0] value in the POST payload.

I checked the module manual, which explains how to use it with CSV import, but not via the API. The REST API docs explain about media ingesters. That led me to search the module code for IngesterInterface and these comments suggest I probably need to pass an ingest_filename parameter somehow. But I’m not sure what the o:ingester should be.

I might experiment later!

The “o:ingester” value to use File Sideload is sideload. And yes, ingest_filename is required and should have as its value a filename within the configured sideload directory.

1 Like

Thank you. I have got the sideloading working nicely. Initially I had some of the files for sideloading in subdirectories so I was setting ingest_filename to things like “subdir/filename.png”. I was annoyed to find that the “subdir/” bit was retained in the o:source property of the media object. The o:source appears in the <title> of the media page as well as the main <h1> of the page. How my files were arranged when I was doing the loading is not something that I want users to be able to see.

Fortunately I found that if I provide an o:source property in the JSON when creating the new media item with a POST request, it overrides the value. So I can create JSON like this:

        media = {
            "o:ingester": "sideload",
            "o:source": os.path.basename(file),
            "o:item": {
                "@id": f"{omeka.api_url}/items/{item_id}",
                "o:id": item_id
            },
            'ingest_filename' = file
        }
        files = [
            ('data', (None, json.dumps(media), 'application/json'))
        ]
        res = omeka.s.post(f"{omeka.api_url}/media", files=files, params=omeka.params)

I then tried updating (with PUT) the small number of media items I had created which included a subdirectory string in o:source, but the API does not allow me to do this. It is also impossible to update the value through the web admin interface.

Why is there this limitation? Is it do do with the default storage arrangements which involve a hash of various properties?

At least I only have four attachments to sort out so far, so I can easily delete and reload.

1 Like