[ckan-dev] CKAN API Clients

Haq, Salman Salman.Haq at neustar.biz
Tue Apr 24 16:08:02 UTC 2012



On 4/24/12 6:36 AM, "Sean Hammond" <sean.hammond at okfn.org> wrote:

>> > Moreover, in my use case, not only does a new resource need to be
>>created
>> > by the CKAN client api, but the resource actually needs to reside on
>>the
>> > CKAN server. I.e. It will need to be uploaded to the filestore. The
>>data
>> > model of a resource only has a 'url' field (presumably for linked
>> > resources) which suggests to me that support for uploading files may
>>not
>> > be a trivial undertaking. Perhaps someone can dispel my hunch?
>> 
>> I've not looked into this part of CKAN before, but I think the place to
>> start would be these chapters of the docs:
>> 
>> http://docs.ckan.org/en/latest/filestore.html
>> 
>> http://docs.ckan.org/en/latest/datastore.html#datastorer
>
>I talked with rossjones about this in the #ckan irc channel. One idea we
>had was that you could just copy your files to a public-readable
>directory on your webserver (e.g. using scp, rsync, etc.) and then use
>the CKAN package_create and package_update API calls to add the files to
>CKAN as 'link to file' resources rather than using CKAN to actually
>upload the file.

That sounds like a plausible suggestion.

I was able to use the REST api to accomplish this using the following
snippet:

c = ckanclient.Client(...)
P = c.package_entity_get('pkgname')
R = dict(name='Test Resource', url='http://...', resource_type='metadata')
P['resources'].append(R)
C.package_entity_put(P)

So this is progress for my project. And like you said, it's not ideal if
the resources are being stored in a location not managed by CKAN's
filestore api, but at least it's something for now.

If somebody can provide me with a concrete example of how to use
package_create and package_update to create a package and an associated
resource, that will be great. It will also help me to add these Action API
functions to the ckanclient library.

Thanks,
Salman


>
>Obviously real resource upload support in CKAN's API would be better.
>The task would be to look into how the web UI handles resource uploading
>and see whether this functionality can be hooked up to the API.
>
>_______________________________________________
>ckan-dev mailing list
>ckan-dev at lists.okfn.org
>http://lists.okfn.org/mailman/listinfo/ckan-dev





More information about the ckan-dev mailing list