GithubHelp home page GithubHelp logo

Uploading a file from url about ckanapi HOT 7 CLOSED

ckan avatar ckan commented on August 30, 2024
Uploading a file from url

from ckanapi.

Comments (7)

wardi avatar wardi commented on August 30, 2024

That's not a file, it's a url. Try urlopen() instead.

from ckanapi.

wardi avatar wardi commented on August 30, 2024

(or just set the url on the resource instead of uploading the file if that's what you prefer)

from ckanapi.

LekanAnni avatar LekanAnni commented on August 30, 2024

Thanks Wardi, i tried the urllib2.urlopen(file), this works fine but the problem here is that its not getting the filename so CKAN cant view the resource.

from ckanapi.

wardi avatar wardi commented on August 30, 2024

You can set a file name explicitly by passing a tuple, e.g. upload=('myfilename.csv', urlopen(url)) This is borrowed from requests http://docs.python-requests.org/en/latest/user/quickstart/#post-a-multipart-encoded-file but works even if you're using LocalCKAN

from ckanapi.

LekanAnni avatar LekanAnni commented on August 30, 2024
	 r = requests.post('http://ckan.org/api/action/resource_create',
                            data={'package_id': package['id'],
                            'name': resourcename,
                            'description': 'some text',
                            'format': extension,
                            'url': 'upload',  # Needed to pass validation
                             },
                      headers={'Authorization': APIKEY},
                     files = {'file': (filename,urllib2.urlopen(pkg_url) )})  
                 # This makes ckan url shows `http://upload` but when i change the filename to "upload", it shows URL: http://ckan.org/dataset/b9f4caa1-be5e-4a02-939e-282acce47306/resource/87211539-e543-412e-bf9a-90084f3a55cb/download/upload 

(without linkage to the file)

image

from ckanapi.

wardi avatar wardi commented on August 30, 2024

your code looks wrong.

files = {'file': (filename,urllib2.urlopen(pkg_url) )}
          ^ this should say 'upload' because it's the field name

filename is where you put your file's name

from ckanapi.

LekanAnni avatar LekanAnni commented on August 30, 2024

Thanks wardi, i got it working now.

from ckanapi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.