Skip to content

Commit 387d7ac

Browse files
committed
use cgi.Filestorage in CKAN version lower than 2.9
1 parent c0372e0 commit 387d7ac

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

ckanext/datapackager/logic/action/create.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,16 +183,20 @@ def _create_and_upload_local_resource(context, resource):
183183
def _create_and_upload_resource(context, resource, the_file):
184184
resource['url'] = 'url'
185185
resource['url_type'] = 'upload'
186-
resource['upload'] = FileStorage(the_file, the_file.name, the_file.name)
186+
187+
if toolkit.check_ckan_version(min_version="2.9"):
188+
resource['upload'] = FileStorage(the_file, the_file.name, the_file.name)
189+
else:
190+
resource['upload'] = _UploadLocalFileStorage(the_file)
187191

188192
toolkit.get_action('resource_create')(context, resource)
189193

190194

191195
def _upload_attribute_is_valid(upload):
192196
return hasattr(upload, 'read') or hasattr(upload, 'file') and hasattr(upload.file, 'read')
193197

194-
195-
class _UploadLocalFileStorage(FileStorage):
198+
# Used only in CKAN < 2.9
199+
class _UploadLocalFileStorage(cgi.FileStorage):
196200
def __init__(self, fp, *args, **kwargs):
197201
self.name = fp.name
198202
self.filename = fp.name

0 commit comments

Comments
 (0)