[ckan-dev] Creating resource with upload from an extension

Pedro G Silva pedro.gracio at deimos.com.pt
Fri May 6 09:38:18 UTC 2016


Regarding this discussion, I'm currently using the ckanapi REMOTE. I tried
to use the localCkan, but yields an error, "TestAppCKAN.call_action does
not support "
                "file uploads, consider contributing it if you need it" .
Maybe you guys can update the code, if you are interested in it. I might
try it when I have the time and the gituhub issue gets fixed

On Fri, Apr 29, 2016 at 3:16 PM, Pedro G Silva <pedro.gracio at deimos.com.pt>
wrote:

> Hi Florian,
> Using your solution does not trigger any errors, however, after uploading,
> the url is 'URL: http://will-be-overwritten-automatically'
> So I guess something else is missing? I'll stick to my ckanapi solution
> for now
>
> On Fri, Apr 29, 2016 at 12:49 PM, <lucia.espona at wsl.ch> wrote:
>
>> Hi
>>
>> I am using CKAN version 2.5.2 and the URL is still required by the
>> FileStore API when creating a new resource.
>> It fails both ommiting the 'url' entry in the input data dictionary as
>> well as setting it to None
>> Instead a random string I preferred to use an empty one, it doesn't
>> matter since it gets replaced by CKAN.
>>
>> Anyway, I guess this won't be necessary for later versions.
>>
>> Cheers,
>> Lucia
>>
>>
>> _________________________________________________________
>> Dr. Lucia Espona Pernas
>>
>> Swiss Federal Institute for Forest, Snow and Landscape Research WSL
>> Hauptgebäaude Labortrakt (HL D34)
>> Zürcherstrasse 111
>> 8903 Birmensdorf
>> Switzerland
>>
>> +41 44 739 28 71 phone direct
>> +41 44 739 21 11 reception
>>
>> www.wsl.ch
>>
>> -----"ckan-dev" <ckan-dev-bounces at lists.okfn.org> wrote: -----
>> To: Pedro G Silva <pedro.gracio at deimos.com.pt>
>> From: Jonas Oppenlaender
>> Sent by: "ckan-dev"
>> Date: 29.04.2016 13:26
>> Cc: CKAN Development Discussions <ckan-dev at lists.okfn.org>
>> Subject: Re: [ckan-dev] Creating resource with upload from an extension
>>
>> Yeah, the url parameter should not be required when doing uploads via the
>> API.
>>
>> See here:
>>
>> https://github.com/ckan/ckan/pull/1641#issuecomment-160893234
>>
>> And here:
>>
>> https://github.com/ckan/ckan/issues/2769
>>
>>
>>
>> Setting it to some random string worked for me, e.g.
>>
>>
>> res = ckan.action.resource_create(
>>          package_id='2ad3c9de-502c-403a-8b03-bfc619697ff2',
>>          url='dummy-value',
>>          name='my file',
>>          description='my upload with CKANAPI',
>>          upload=open('./myfile.csv')
>>      )
>>
>>
>>
>> Best regards,
>>
>> Jonas Oppenlaender
>>
>>
>>
>>
>>
>> *From: *Pedro G Silva <pedro.gracio at deimos.com.pt>
>> *Sent: *28 April 2016 14:11
>> *To: *Jonas Oppenlaender <jonas.oppenlaender at seme4.com>
>> *Cc: *CKAN Development Discussions <ckan-dev at lists.okfn.org>
>> *Subject: *Re: [ckan-dev] Creating resource with upload from an extension
>>
>>
>>
>> Hi
>>
>> Your solution does not produce any error, although if I have resource_dict['url']
>> = None,
>> [ckanext.harvest.model] Validation Error: {'URL': 'Missing value'}
>>
>>
>>
>> If I had a value I get that value on the resource link, not a resource
>> pointing to the filestore (or ckan internal storage).
>>
>>
>>
>> Any ideas?
>>
>> I'm thinking on using the API inside the extension, but this is a very
>> hacky solution..
>>
>>
>>
>> On Wed, Apr 27, 2016 at 7:29 PM, Jonas Oppenlaender <
>> jonas.oppenlaender at seme4.com> wrote:
>>
>> Hi Pedro,
>>
>>
>>
>> You can just pass it an open file pointer, like this:
>>
>> resource_dict['upload'] = open(‘/path/to/file’, ‘rb’)
>>
>>
>>
>> If you use an already open file, you might need to reset the current
>> position before calling the API:
>>
>> existingfilepointer.seek(0)
>>
>>
>>
>> Regards,
>>
>> Jonas Oppenlaender
>>
>>
>>
>>
>>
>>
>>
>> *From: *Pedro G Silva <pedro.gracio at deimos.com.pt>
>> *Sent: *27 April 2016 17:51
>> *To: *CKAN Development Discussions <ckan-dev at lists.okfn.org>
>> *Subject: *[ckan-dev] Creating resource with upload from an extension
>>
>>
>>
>> Hi
>>
>> I have a custom extension which does some parsing on files and then adds
>> them to the dataset created. How should I use the field upload to pass a
>> file? Any ideas?
>>
>>
>>
>> resource_dict={}
>>
>> resource_dict['package_id'] = package_id
>>
>> resource_dict['upload'] = ????
>>
>> resource_dict['name'] = 'Product Download'
>>
>> oi = plugins.toolkit.get_action('resource_create')(context,resource_dict)
>>
>>
>>
>> --
>>
>>
>>
>>
>>
>> [image: DEIMOS Engenharia, SA] <http://www.deimos.pt>
>>
>> *Pedro Gracio Silva*
>> Aerospace Systems / Production Center
>>
>> *Av. D. Joao II, Lt 1.17.01, 10 • 1998-023 Lisboa, Portugal*
>> Ph: +351 21 893 3020 • Fax: +351 21 896 9099
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> --
>>
>>
>>
>>
>>
>> [image: DEIMOS Engenharia, SA] <http://www.deimos.pt>
>>
>> *Pedro Gracio Silva*
>> Aerospace Systems / Production Center
>>
>> *Av. D. Joao II, Lt 1.17.01, 10 • 1998-023 Lisboa, Portugal*
>> Ph: +351 21 893 3020 • Fax: +351 21 896 9099
>>
>>
>>
>>
>>
>>
>> _______________________________________________
>> ckan-dev mailing list
>> ckan-dev at lists.okfn.org
>> https://lists.okfn.org/mailman/listinfo/ckan-dev
>> Unsubscribe: https://lists.okfn.org/mailman/options/ckan-dev
>>
>> _______________________________________________
>> ckan-dev mailing list
>> ckan-dev at lists.okfn.org
>> https://lists.okfn.org/mailman/listinfo/ckan-dev
>> Unsubscribe: https://lists.okfn.org/mailman/options/ckan-dev
>>
>>
>
>
> --
>
>
> [image: DEIMOS Engenharia, SA] <http://www.deimos.pt>
> *Pedro Gracio Silva*
> Aerospace Systems / Production Center
>
> *Av. D. Joao II, Lt 1.17.01, 10 • 1998-023 Lisboa, Portugal*
> Ph: +351 21 893 3020 • Fax: +351 21 896 9099
>
>


-- 


[image: DEIMOS Engenharia, SA] <http://www.deimos.pt>
*Pedro Gracio Silva*
Aerospace Systems / Production Center

*Av. D. Joao II, Lt 1.17.01, 10 • 1998-023 Lisboa, Portugal*
Ph: +351 21 893 3020 • Fax: +351 21 896 9099
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.okfn.org/pipermail/ckan-dev/attachments/20160506/980187cf/attachment-0002.html>


More information about the ckan-dev mailing list