ckan

How create an organization in CKAN with an image through the API lik it's possible with web interface


In CKAN when creating an organization with the web interface, it's possible to provide an image_url or select a image on our local disk. With this 2nd choice, the image is uploaded and the organisation has the link to the image.

With the CKAN API there is only a parameter image_url, and I can't find a solution to upload an image with the API.

How can I upload an image to provide the image_url paramater to the API ?

I tried to look for the API, but I only found resource API that is not adapted for this need. And I found nothing in the doc or forums.


Solution

  • I answer to my question:

    1. Create an organisation myorg without image (necessary for the step 2)
    2. Create a dataset attached to the previous organisation
    curl --location --request POST 'http://localhost:5001/api/3/action/package_create' \
    --form 'name="myds"' \
    --form 'owner_org="myorg"'
    
    1. Upload the image using the Filestore api:
    curl --location --request POST 'http://localhost:5001/api/3/action/resource_create' \
    --form 'package_id="myds"' \
    --form 'upload=@"./myimage.jpg"' \
    --form 'name="myimage.jpg"'
    

    Retrieve the URL from the response

    You now have an URL for the resource, and you can use it to update the organisation or create a new one.