Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

For more complex interactions such as file uploads, we may be much better off using the ckanclient in Python: https://stackoverflow.com/questions/14947468/uploading-a-file-through-ckans-api-1-8-how-to-do-it

If you're just learning or trying new things out, take a look at the CKAN FileStore docs: http://docs.ckan.org/en/ckan-2.7.3/maintaining/filestore.html#filestore-api

For example, you can upload a file using curl with the following syntax:

Code Block
languagebash
$ curl 'https://demo.ckan.org/api/action/resource_create' -H "Authorization:<API_KEY>" --form upload=@<FILE_TO_UPLOAD> --form package_id=<DATASET_NAME_TO_ATTACH_FILE>
{"help": "https://demo.ckan.org/api/3/action/help_show?name=resource_create", "success": true, "result": {"cache_last_updated": null, "cache_url": null, "mimetype_inner": null, "hash": "", "description": "", "format": "PNG", "url": "https://demo.ckan.org/dataset/a09f9319-bf4c-48a0-8d98-a8d066d6636d/resource/526301cc-aaa3-423c-9159-3741fef913dc/download/tux-copy.png", "created": "2018-08-14T15:09:03.441040", "state": "active", "package_id": "a09f9319-bf4c-48a0-8d98-a8d066d6636d", "last_modified": null, "mimetype": null, "url_type": "upload", "position": 0, "revision_id": "7fda82dd-b0c7-42a0-a06d-01cb9685f290", "size": null, "datastore_active": false, "id": "526301cc-aaa3-423c-9159-3741fef913dc", "resource_type": null, "name": null}}