Skip to content

Commit

Permalink
Merge pull request #14 from apivideo/fix-chunk-size
Browse files Browse the repository at this point in the history
Fix chunks size
  • Loading branch information
bot-api-video authored Aug 17, 2021
2 parents 7f9e593 + e7ca079 commit 5a66de7
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 9 deletions.
2 changes: 1 addition & 1 deletion apivideo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"""


__version__ = "0.0.12"
__version__ = "0.0.13"

# import ApiVideoClient
from apivideo.auth_api_client import AuthenticatedApiClient
Expand Down
2 changes: 1 addition & 1 deletion apivideo/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def __init__(self, configuration=None, header_name=None, header_value=None,
self.default_headers[header_name] = header_value
self.cookie = cookie
# Set default User-Agent.
self.user_agent = '"api.video client (python; v:0.0.12; )"'
self.user_agent = '"api.video client (python; v:0.0.13; )"'

def __enter__(self):
return self
Expand Down
11 changes: 9 additions & 2 deletions apivideo/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
'minLength', 'pattern', 'maxItems', 'minItems'
}

DEFAULT_CHUNK_SIZE = 50 * 1024 * 1024
MIN_CHUNK_SIZE = 5 * 1024 * 1024
MAX_CHUNK_SIZE = 128 * 1024 * 1024

class Configuration(object):
"""
:param host: Base url
Expand Down Expand Up @@ -85,7 +89,7 @@ def __init__(self, host=None,
server_index=None, server_variables=None,
server_operation_index=None, server_operation_variables=None,
ssl_ca_cert=None,
chunk_size=1024 * 1024,
chunk_size=DEFAULT_CHUNK_SIZE,
):
"""Constructor
"""
Expand Down Expand Up @@ -192,6 +196,9 @@ def __init__(self, host=None,
self.socket_options = None

# chunk size for upload
if chunk_size < MIN_CHUNK_SIZE or chunk_size > MAX_CHUNK_SIZE:
raise ValueError(
"Invalid chunk size value. Must be greater than {0} bytes and lower than {1} bytes.".format(MIN_CHUNK_SIZE, MAX_CHUNK_SIZE))
self.chunk_size = chunk_size

def __deepcopy__(self, memo):
Expand Down Expand Up @@ -384,7 +391,7 @@ def to_debug_report(self):
"OS: {env}\n"\
"Python Version: {pyversion}\n"\
"Version of the API: 1\n"\
"SDK Package Version: 0.0.12".\
"SDK Package Version: 0.0.13".\
format(env=sys.platform, pyversion=sys.version)

def get_host_settings(self):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from setuptools import setup, find_packages # noqa: H301

NAME = "api.video"
VERSION = "0.0.12"
VERSION = "0.0.13"
# To install the library, run the following
#
# python setup.py install
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion test/test_integration_raw_statistics_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def test_list_video_sessions_metadata(self):
Metadata(key="user", value='__user__')
]))

file = open("sample.mp4", "rb")
file = open("558k.mp4", "rb")
self.videoApi.upload(video.video_id, file, _request_timeout=20)
file.close()

Expand Down
6 changes: 3 additions & 3 deletions test/test_integration_videos_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def listener(uploaded, total):
public=True,
tags=["bunny"]))

file = open("sample-mp4-file.mp4", "rb")
file = open("10m.mp4", "rb")
self.api.upload(video.video_id, file, _request_timeout=20, _progress_listener=listener)
file.close()
self.api.delete(video.video_id)
Expand All @@ -75,7 +75,7 @@ def test_upload_temporary_file(self):
public=True,
tags=["bunny"]))

file = open("sample.mp4", "rb")
file = open("558k.mp4", "rb")
with tempfile.SpooledTemporaryFile(mode="wb") as temp:
temp.write(file.read())
self.api.upload(video.video_id, temp, _request_timeout=20)
Expand All @@ -89,7 +89,7 @@ def test_upload_chunks(self):
public=True,
tags=["bunny"]))

file = open("sample-mp4-file.mp4", "rb")
file = open("10m.mp4", "rb")
self.api.upload(video.video_id, file, _request_timeout=20)
file.close()
self.api.delete(video.video_id)

0 comments on commit 5a66de7

Please sign in to comment.