-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Why do we need to pass an URL when uploading a resource? #2769
Comments
CKAN requires a "url" on "resource_create", even if it's not used (i.e. when we're uploading a file). This might be solved in ckan/ckan#2769. To avoid making the user deal with this problem, we deal with it ourselves.
CKAN requires a "url" on "resource_create", even if it's not used (i.e. when we're uploading a file). This might be solved in ckan/ckan#2769. To avoid making the user deal with this problem, we deal with it ourselves.
this is really broken for me. Uploading resources simply doesn't work. If I supply no url, CKAN cracks out on me and won't let me upload my resource. If I supply a url like ' ', the view resource button goes to 'http://' and doesn't work. If I supply a url like '', it's treated as not existing. I simply can't believe this is a bug in production CKAN right now. Uploading files is surely an important feature. |
@CarlQLange are you saying that the change in ckan/ckanapi#74 doesn't work? Doesn't an uploaded file cause the url value to be replaced for you? |
No it doesn’t – it experienced it with version 2.4.1 and 2.5.1 as well. De : Ian Ward [mailto:notifications@github.com] @CarlQLangehttps://github.com/CarlQLange are you saying that the change in ckan/ckanapi#74ckan/ckanapi#74 doesn't work? Doesn't an uploaded file cause the url value to be replaced for you? — Ce message et ses pieces jointes peuvent contenir des informations confidentielles ou privilegiees et ne doivent donc This message and its attachments may contain confidential or privileged information that may be protected by law; |
I remembered the fix for this. I'm using requests: r = requests.post('%s/api/action/resource_create' % (API_HOST),
data={
"package_id": dataset_name,
"type": "file.upload",
"url": "anything",
"name": resource_name,
"format": resource_format
},
headers={"Authorization": API_KEY},
files=[('upload', file(resource_path))]) #HERE The trick is to be sure the name of the uploaded file is 'upload', and only that. Anything else will cause this to break. Sorry about my saltiness, just under deadline and having something simple break :) |
@CarlQLange don't worry about it. You might want to give ckanapi a try (when not under deadline). It's a very small library and it gives you real python exceptions when there are errors in your requests. |
Just in case I forget how I fixed this in future: r = requests.post('%s/api/action/resource_create' % (API_HOST),
data={
"package_id": dataset_name,
"type": "file.upload",
"url": "",
"name": resource_name,
"format": resource_format
},
headers={"Authorization": API_KEY},
files={'upload': (resource_name, file(resource_path))}) The tuple in |
Hi there, Actually it would appear that the correct parameters are r = requests.post('%s/api/action/resource_create' % (API_HOST),
I just tested it from Java client, with dummyfile.txt for upload. The API generates a new URL for download such as Marc-Antoine De : Carl Lange [mailto:notifications@github.com] I remembered the fix for this. I'm using requests: r = requests.post('%s/api/action/resource_create' % (API_HOST),
The trick is to be sure the name of the uploaded file is 'upload', and only that. Anything else will cause this to break. Sorry about my saltiness, just under deadline and having something simply break :) — Ce message et ses pieces jointes peuvent contenir des informations confidentielles ou privilegiees et ne doivent donc This message and its attachments may contain confidential or privileged information that may be protected by law; |
fixed by #2844 |
According to https://github.com/ckan/ckanapi docs, we should be able to upload a new resource with:
This doesn't work, because
resource_create
requires anurl
parameter. Blaming thecreate.py
file, I found out that this validation was added by 072b62b5 (which, curiously, was made by me 😅 ). It is quite old (Apr/2014).Probably the correct solution at the time would be to fix the docs, which says that the URL is required.
The text was updated successfully, but these errors were encountered: