[ckan-dev] Upload file through the API.

Henrik Aagaard Sørensen BU1G at tmf.kk.dk
Tue Sep 24 07:39:37 UTC 2013


Just to answer myself and ask for some other help, this code works for uploading a file to a package (not a ressource):

ckan = ckanclient.CkanClient(base_location=CKAN-URL', api_key=CKAN-API-KEY)
ckan.upload_file(FILENAME)
ckan.add_package_resource(DATASET, FILENAME, name=FILENAME, resource_type='data', format='csv')

However, when running the code multiple times, for updating the dataset with a new file, it fails with the following:

Traceback (most recent call last):
  File "oracle_csv_ckan.py", line 27, in <module>
    ckan.add_package_resource(DATASET, FILENAME, name=FILENAME, resource_type='data', format='csv')
  File "ckanclient/ckanclient/__init__.py", line 630, in add_package_resource
    url, msg = self.upload_file(file_path)
  File "ckanclient/ckanclient/__init__.py", line 577, in upload_file
    auth_dict = self.storage_auth_get('/form/'+file_key, {})
  File "ckanclient/ckanclient/__init__.py", line 447, in storage_auth_get
    self.open_url(url, payload, method="POST")
  File "ckanclient/ckanclient/__init__.py", line 203, in open_url
    raise CkanApiConflictError(self.last_status)
ckanclient.CkanApiConflictError: 409

Is this due to the fact that I've already uploaded a file with the same name?

How can I just replace/update a file from a resource?

I would like to replace a specific package resource as developers most likely are using the resource ID for getting data, and then I cannot just delete a file and upload a new. I need to replace the data in an existing resource.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.okfn.org/pipermail/ckan-dev/attachments/20130924/9f91eb7e/attachment-0001.html>


More information about the ckan-dev mailing list