[ckan-dev] Wrong URL after file upload

Richard Gomes rgomes.info at gmail.com
Tue Sep 3 12:58:04 UTC 2013


For the time being, I'm calling twice the method which associates 
resources to a given dataset.
The second time it is called, it fixes URLs of resources.
OK. It works, but it looks dirty to me :(

Any suggestion is highly appreciated.

Thanks

def populate_package(cli, pkg, folder, mimetype):
     for root, file in filelist(folder):
         q='%s:%s' % ( 'name', file )
         print(q)
         r = cli.resource_search(query=q)
         if r['count'] == 0:
             path = '%s/%s' % (root, file)
             print('create', path)
             cli.add_package_resource(pkg, path, resource_type='data', 
mimetype=mimetype)
*elif r['count'] == 1:*
             url = r['results'][0]['url']
             if url.find(site_url) == -1:
*                url = url.replace('http:/', site_url)
cli.resource_update(id=r['results'][0]['id'], url=url)**
*                print('update', url)
             else:
                 print('info', url)
         else:
             raise RuntimeError(file + ' :: too many entries')



Richard Gomes
http://rgomes.info
http://www.linkedin.com/in/rgomes
mobile: +44(77)9955-6813
inum <http://www.inum.net/>: +883(5100)0800-9804

On 03/09/13 13:02, Richard Gomes wrote:
> hello,
>
> I'm uploading files like this:
>
>     cli = ckanclient.CkanClient( ... )
>     pkg = 'my dataset'
>     path = '/home/rgomes/tmp/my.csv'
>     mimetype = 'text/csv'
>     cli.add_package_resource(pkg, path, resource_type='data',
>     mimetype=mimetype)
>
> Apparently it works fine.
>
> But in the web interface (CKAN website), the URL for the resource 
> misses the CKAN site_url in it, for example:
>     URL: 
> http://storage/f/2013-09-03T115539/Kolanovic-et-al.---Rise-of-Cross-Asset-Correlations.pdf
> ... whilst it should be:
>     URL: 
> http://*ckan.localdomain:5000/*storage/f/2013-09-03T115539/Kolanovic-et-al.---Rise-of-Cross-Asset-Correlations.pdf 
> <http://storage/f/2013-09-03T115539/Kolanovic-et-al.---Rise-of-Cross-Asset-Correlations.pdf>
>
> What would be a _/recommended/_ way to fix this?
>
> By /_recommended_/ I mean: best practices. Should I use DataStorer 
> instead? Can it be considered mature enough?
>
> Thanks a lot :)
>
>
> Richard Gomes
> http://rgomes.info
> http://www.linkedin.com/in/rgomes
> mobile: +44(77)9955-6813
> inum <http://www.inum.net/>: +883(5100)0800-9804
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.okfn.org/pipermail/ckan-dev/attachments/20130903/17a9ff0e/attachment-0001.html>


More information about the ckan-dev mailing list