Skip to content
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

Put range from url #7081

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ class QueryStringConstants(object):
END_RK = 'erk'
SIGNED_RESOURCE_TYPES = 'srt'
SIGNED_SERVICES = 'ss'
SIGNED_OID = 'skoid'
SIGNED_TID = 'sktid'
SIGNED_KEY_START = 'skt'
SIGNED_KEY_EXPIRY = 'ske'
SIGNED_KEY_SERVICE = 'sks'
SIGNED_KEY_VERSION = 'skv'

@staticmethod
def to_list():
Expand All @@ -70,6 +76,12 @@ def to_list():
QueryStringConstants.END_RK,
QueryStringConstants.SIGNED_RESOURCE_TYPES,
QueryStringConstants.SIGNED_SERVICES,
QueryStringConstants.SIGNED_OID,
QueryStringConstants.SIGNED_TID,
QueryStringConstants.SIGNED_KEY_START,
QueryStringConstants.SIGNED_KEY_EXPIRY,
QueryStringConstants.SIGNED_KEY_SERVICE,
QueryStringConstants.SIGNED_KEY_VERSION,
]


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ class QueryStringConstants(object):
END_RK = 'erk'
SIGNED_RESOURCE_TYPES = 'srt'
SIGNED_SERVICES = 'ss'
SIGNED_OID = 'skoid'
SIGNED_TID = 'sktid'
SIGNED_KEY_START = 'skt'
SIGNED_KEY_EXPIRY = 'ske'
SIGNED_KEY_SERVICE = 'sks'
SIGNED_KEY_VERSION = 'skv'

@staticmethod
def to_list():
Expand All @@ -70,6 +76,12 @@ def to_list():
QueryStringConstants.END_RK,
QueryStringConstants.SIGNED_RESOURCE_TYPES,
QueryStringConstants.SIGNED_SERVICES,
QueryStringConstants.SIGNED_OID,
QueryStringConstants.SIGNED_TID,
QueryStringConstants.SIGNED_KEY_START,
QueryStringConstants.SIGNED_KEY_EXPIRY,
QueryStringConstants.SIGNED_KEY_SERVICE,
QueryStringConstants.SIGNED_KEY_VERSION,
]


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,57 @@ async def upload_range( # type: ignore
except StorageErrorException as error:
process_storage_error(error)

@distributed_trace_async
async def upload_range_from_url(self, source_url, # type: str
range_start, # type: int
range_end, # type: int
source_range_start, # type: int
**kwargs # type: Any
):
# type: (str, int, int, int, **Any) -> Dict[str, Any]
'''
Writes the bytes from one Azure File endpoint into the specified range of another Azure File endpoint.

:param int range_start:
Start of byte range to use for updating a section of the file.
The range can be up to 4 MB in size.
The start_range and end_range params are inclusive.
Ex: start_range=0, end_range=511 will download first 512 bytes of file.
:param int range_end:
End of byte range to use for updating a section of the file.
The range can be up to 4 MB in size.
The start_range and end_range params are inclusive.
Ex: start_range=0, end_range=511 will download first 512 bytes of file.
:param str source_url:
A URL of up to 2 KB in length that specifies an Azure file or blob.
The value should be URL-encoded as it would appear in a request URI.
If the source is in another account, the source must either be public
or must be authenticated via a shared access signature. If the source
is public, no authentication is required.
Examples:
https://myaccount.file.core.windows.net/myshare/mydir/myfile
https://otheraccount.file.core.windows.net/myshare/mydir/myfile?sastoken
:param int source_range_start:
Start of byte range to use for updating a section of the file.
The range can be up to 4 MB in size.
The start_range and end_range params are inclusive.
Ex: start_range=0, end_range=511 will download first 512 bytes of file.
:param int timeout:
The timeout parameter is expressed in seconds.
'''

options = self._upload_range_from_url_options(
source_url=source_url,
range_start=range_start,
range_end=range_end,
source_range_start=source_range_start,
**kwargs
)
try:
return await self._client.file.upload_range_from_url(**options) # type: ignore
except StorageErrorException as error:
process_storage_error(error)

@distributed_trace_async
async def get_ranges( # type: ignore
self,
Expand Down
79 changes: 78 additions & 1 deletion sdk/storage/azure-storage-file/azure/storage/file/file_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# --------------------------------------------------------------------------

# pylint: disable=too-many-lines
import functools
from io import BytesIO
from typing import ( # pylint: disable=unused-import
Expand Down Expand Up @@ -753,6 +753,83 @@ def upload_range( # type: ignore
except StorageErrorException as error:
process_storage_error(error)

@staticmethod
def _upload_range_from_url_options(source_url, # type: str
range_start, # type: int
range_end, # type: int
source_range_start, # type: int
**kwargs
):
# type: (...) -> Dict[str, Any]

if range_start is None or range_end is None or source_range_start is None:
raise ValueError("start_range must be specified")

# Format range
destination_range = 'bytes={0}-{1}'.format(range_start, range_end)
source_range = 'bytes={0}-{1}'.format(source_range_start, source_range_start + (range_end - range_start))

options = {
'copy_source': source_url,
'content_length': 0,
'source_range': source_range,
'range': destination_range,
'timeout': kwargs.pop('timeout', None),
'cls': return_response_headers}
options.update(kwargs)
return options

@distributed_trace
def upload_range_from_url(self, source_url, # type: str
range_start, # type: int
range_end, # type: int
source_range_start, # type: int
**kwargs # type: Any
):
# type: (str, int, int, int, **Any) -> Dict[str, Any]
'''
Writes the bytes from one Azure File endpoint into the specified range of another Azure File endpoint.

:param int range_start:
Start of byte range to use for updating a section of the file.
The range can be up to 4 MB in size.
The start_range and end_range params are inclusive.
Ex: start_range=0, end_range=511 will download first 512 bytes of file.
:param int range_end:
End of byte range to use for updating a section of the file.
The range can be up to 4 MB in size.
The start_range and end_range params are inclusive.
Ex: start_range=0, end_range=511 will download first 512 bytes of file.
:param str source_url:
A URL of up to 2 KB in length that specifies an Azure file or blob.
The value should be URL-encoded as it would appear in a request URI.
If the source is in another account, the source must either be public
or must be authenticated via a shared access signature. If the source
is public, no authentication is required.
Examples:
https://myaccount.file.core.windows.net/myshare/mydir/myfile
https://otheraccount.file.core.windows.net/myshare/mydir/myfile?sastoken
:param int source_range_start:
Start of byte range to use for updating a section of the file.
The range can be up to 4 MB in size.
The start_range and end_range params are inclusive.
Ex: start_range=0, end_range=511 will download first 512 bytes of file.
:param int timeout:
The timeout parameter is expressed in seconds.
'''

options = self._upload_range_from_url_options(
source_url=source_url,
range_start=range_start,
range_end=range_end,
source_range_start=source_range_start,
**kwargs
)
try:
return self._client.file.upload_range_from_url(**options) # type: ignore
except StorageErrorException as error:
process_storage_error(error)

@distributed_trace
def get_ranges( # type: ignore
self, start_range=None, # type: Optional[int]
Expand Down

Large diffs are not rendered by default.

Loading