Skip to content

Commit

Permalink
Merge pull request #35 from vrk-kpa/add_ckan_2.8_support
Browse files Browse the repository at this point in the history
Add CKAN 2.8 support
  • Loading branch information
TkTech authored Jan 8, 2020
2 parents 39cbc62 + 8e99139 commit dc5ece6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
9 changes: 8 additions & 1 deletion ckanext/cloudstorage/logic/action/multipart.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,17 @@

from ckanext.cloudstorage.storage import ResourceCloudStorage
from ckanext.cloudstorage.model import MultipartUpload, MultipartPart
from werkzeug.datastructures import FileStorage as FlaskFileStorage

log = logging.getLogger(__name__)


def _get_underlying_file(wrapper):
if isinstance(wrapper, FlaskFileStorage):
return wrapper.stream
return wrapper.file


def _get_max_multipart_lifetime():
value = float(config.get('ckanext.cloudstorage.max_multipart_lifetime', 7))
return datetime.timedelta(value)
Expand Down Expand Up @@ -152,7 +159,7 @@ def upload_multipart(context, data_dict):
uploader, upload.name) + '?partNumber={0}&uploadId={1}'.format(
part_number, upload_id),
method='PUT',
data=bytearray(part_content.file.read())
data=bytearray(_get_underlying_file(part_content).read())
)
if resp.status != 200:
raise toolkit.ValidationError('Upload failed: part %s' % part_number)
Expand Down
14 changes: 12 additions & 2 deletions ckanext/cloudstorage/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@
from libcloud.storage.providers import get_driver


from werkzeug.datastructures import FileStorage as FlaskFileStorage
ALLOWED_UPLOAD_TYPES = (cgi.FieldStorage, FlaskFileStorage)


def _get_underlying_file(wrapper):
if isinstance(wrapper, FlaskFileStorage):
return wrapper.stream
return wrapper.file


class CloudStorage(object):
def __init__(self):
self.driver = get_driver(
Expand Down Expand Up @@ -162,9 +172,9 @@ def __init__(self, resource):
multipart_name = resource.pop('multipart_name', None)

# Check to see if a file has been provided
if isinstance(upload_field_storage, cgi.FieldStorage):
if isinstance(upload_field_storage, (ALLOWED_UPLOAD_TYPES)):
self.filename = munge.munge_filename(upload_field_storage.filename)
self.file_upload = upload_field_storage.file
self.file_upload = _get_underlying_file(upload_field_storage)
resource['url'] = self.filename
resource['url_type'] = 'upload'
elif multipart_name and self.can_use_advanced_aws:
Expand Down

0 comments on commit dc5ece6

Please sign in to comment.