Skip to content

[Storage] [STG 100] Create File with Data #42450

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

Open
wants to merge 6 commits into
base: feature/storage-stg100
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion sdk/storage/azure-storage-file-share/assets.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"AssetsRepo": "Azure/azure-sdk-assets",
"AssetsRepoPrefixPath": "python",
"TagPrefix": "python/storage/azure-storage-file-share",
"Tag": "python/storage/azure-storage-file-share_9c32ba27e3"
"Tag": "python/storage/azure-storage-file-share_36a6ac44cc"
}
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,16 @@ def create_directory(self, **kwargs: Any) -> Dict[str, Any]:
NFS only. The owning group of the directory.
:keyword str file_mode:
NFS only. The file mode of the directory.
:keyword file_property_semantics:
SMB only. Specifies permissions to be configured. Default value is None.
If not specified or None is passed, New will be the default. Possible values are:

New - forcefully add the ARCHIVE attribute flag and alter the permissions specified in
x-ms-file-permission to inherit missing permissions from the parent.

Restore - apply changes without further modification.

:paramtype file_property_semantics: Literal["New", "Restore"]
:keyword int timeout:
Sets the server-side timeout for the operation in seconds. For more details see
https://learn.microsoft.com/rest/api/storageservices/setting-timeouts-for-file-service-operations.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,18 @@ def create_file(
NFS only. The owning group of the file.
:keyword str file_mode:
NFS only. The file mode of the file.
:keyword file_property_semantics:
SMB only. Specifies permissions to be configured. Default value is None.
If not specified or None is passed, New will be the default. Possible values are:

New - forcefully add the ARCHIVE attribute flag and alter the permissions specified in
x-ms-file-permission to inherit missing permissions from the parent.

Restore - apply changes without further modification.

:paramtype file_property_semantics: Literal["New", "Restore"]
:keyword IO[bytes] data: Initial data to upload. The limit is 4MB.
:keyword int length: Specifies the number of bytes being uploaded in the initial data.
:keyword int timeout:
Sets the server-side timeout for the operation in seconds. For more details see
https://learn.microsoft.com/rest/api/storageservices/setting-timeouts-for-file-service-operations.
Expand Down Expand Up @@ -485,6 +497,8 @@ def create_file(
file_permission=file_permission,
file_permission_key=permission_key,
file_http_headers=file_http_headers,
optionalbody=kwargs.pop('data', None),
content_length=kwargs.pop('length', None),
lease_access_conditions=access_conditions,
headers=headers,
timeout=timeout,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class AzureFileStorage: # pylint: disable=client-accepts-api-version-keyword
URI. Default value is None.
:type allow_source_trailing_dot: bool
:keyword version: Specifies the version of the operation to use for this request. Default value
is "2025-11-05". Note that overriding this default value may result in unsupported behavior.
is "2026-02-06". Note that overriding this default value may result in unsupported behavior.
:paramtype version: str
:keyword file_range_write_from_url: Only update is supported: - Update: Writes the bytes
downloaded from the source url into the specified range. Default value is "update". Note that
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class AzureFileStorageConfiguration: # pylint: disable=too-many-instance-attrib
URI. Default value is None.
:type allow_source_trailing_dot: bool
:keyword version: Specifies the version of the operation to use for this request. Default value
is "2025-11-05". Note that overriding this default value may result in unsupported behavior.
is "2026-02-06". Note that overriding this default value may result in unsupported behavior.
:paramtype version: str
:keyword file_range_write_from_url: Only update is supported: - Update: Writes the bytes
downloaded from the source url into the specified range. Default value is "update". Note that
Expand All @@ -49,7 +49,7 @@ def __init__(
allow_source_trailing_dot: Optional[bool] = None,
**kwargs: Any
) -> None:
version: Literal["2025-11-05"] = kwargs.pop("version", "2025-11-05")
version: Literal["2026-02-06"] = kwargs.pop("version", "2026-02-06")
file_range_write_from_url: Literal["update"] = kwargs.pop("file_range_write_from_url", "update")

if url is None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class AzureFileStorage: # pylint: disable=client-accepts-api-version-keyword
URI. Default value is None.
:type allow_source_trailing_dot: bool
:keyword version: Specifies the version of the operation to use for this request. Default value
is "2025-11-05". Note that overriding this default value may result in unsupported behavior.
is "2026-02-06". Note that overriding this default value may result in unsupported behavior.
:paramtype version: str
:keyword file_range_write_from_url: Only update is supported: - Update: Writes the bytes
downloaded from the source url into the specified range. Default value is "update". Note that
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class AzureFileStorageConfiguration: # pylint: disable=too-many-instance-attrib
URI. Default value is None.
:type allow_source_trailing_dot: bool
:keyword version: Specifies the version of the operation to use for this request. Default value
is "2025-11-05". Note that overriding this default value may result in unsupported behavior.
is "2026-02-06". Note that overriding this default value may result in unsupported behavior.
:paramtype version: str
:keyword file_range_write_from_url: Only update is supported: - Update: Writes the bytes
downloaded from the source url into the specified range. Default value is "update". Note that
Expand All @@ -49,7 +49,7 @@ def __init__(
allow_source_trailing_dot: Optional[bool] = None,
**kwargs: Any
) -> None:
version: Literal["2025-11-05"] = kwargs.pop("version", "2025-11-05")
version: Literal["2026-02-06"] = kwargs.pop("version", "2026-02-06")
file_range_write_from_url: Literal["update"] = kwargs.pop("file_range_write_from_url", "update")

if url is None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ async def create(
owner: Optional[str] = None,
group: Optional[str] = None,
file_mode: Optional[str] = None,
file_property_semantics: Optional[Union[str, _models.FilePropertySemantics]] = None,
**kwargs: Any
) -> None:
"""Creates a new directory under the specified share or parent directory.
Expand Down Expand Up @@ -126,6 +127,11 @@ async def create(
:param file_mode: Optional, NFS only. The file mode of the file or directory. Default value is
None.
:type file_mode: str
:param file_property_semantics: SMB only, default value is New. New will forcefully add the
ARCHIVE attribute flag and alter the permissions specified in x-ms-file-permission to inherit
missing permissions from the parent. Restore will apply changes without further modification.
Known values are: "New" and "Restore". Default value is None.
:type file_property_semantics: str or ~azure.storage.fileshare.models.FilePropertySemantics
:return: None or the result of cls(response)
:rtype: None
:raises ~azure.core.exceptions.HttpResponseError:
Expand Down Expand Up @@ -158,6 +164,7 @@ async def create(
owner=owner,
group=group,
file_mode=file_mode,
file_property_semantics=file_property_semantics,
allow_trailing_dot=self._config.allow_trailing_dot,
file_request_intent=self._config.file_request_intent,
restype=restype,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,12 @@ async def create(
group: Optional[str] = None,
file_mode: Optional[str] = None,
nfs_file_type: Optional[Union[str, _models.NfsFileType]] = None,
content_md5: Optional[bytes] = None,
file_property_semantics: Optional[Union[str, _models.FilePropertySemantics]] = None,
content_length: Optional[int] = None,
file_http_headers: Optional[_models.FileHTTPHeaders] = None,
lease_access_conditions: Optional[_models.LeaseAccessConditions] = None,
optionalbody: Optional[IO[bytes]] = None,
**kwargs: Any
) -> None:
"""Creates a new file or replaces a file. Note it only initializes the file with no content.
Expand Down Expand Up @@ -149,10 +153,26 @@ async def create(
:param nfs_file_type: Optional, NFS only. Type of the file or directory. Known values are:
"Regular", "Directory", and "SymLink". Default value is None.
:type nfs_file_type: str or ~azure.storage.fileshare.models.NfsFileType
:param content_md5: An MD5 hash of the content. This hash is used to verify the integrity of
the data during transport. When the Content-MD5 header is specified, the File service compares
the hash of the content that has arrived with the header value that was sent. If the two hashes
do not match, the operation will fail with error code 400 (Bad Request). Default value is None.
:type content_md5: bytes
:param file_property_semantics: SMB only, default value is New. New will forcefully add the
ARCHIVE attribute flag and alter the permissions specified in x-ms-file-permission to inherit
missing permissions from the parent. Restore will apply changes without further modification.
Known values are: "New" and "Restore". Default value is None.
:type file_property_semantics: str or ~azure.storage.fileshare.models.FilePropertySemantics
:param content_length: Specifies the number of bytes being transmitted in the request body.
When the x-ms-write header is set to clear, the value of this header must be set to zero.
Default value is None.
:type content_length: int
:param file_http_headers: Parameter group. Default value is None.
:type file_http_headers: ~azure.storage.fileshare.models.FileHTTPHeaders
:param lease_access_conditions: Parameter group. Default value is None.
:type lease_access_conditions: ~azure.storage.fileshare.models.LeaseAccessConditions
:param optionalbody: Initial data. Default value is None.
:type optionalbody: IO[bytes]
:return: None or the result of cls(response)
:rtype: None
:raises ~azure.core.exceptions.HttpResponseError:
Expand All @@ -169,6 +189,7 @@ async def create(
_params = kwargs.pop("params", {}) or {}

file_type_constant: Literal["file"] = kwargs.pop("file_type_constant", _headers.pop("x-ms-type", "file"))
content_type: str = kwargs.pop("content_type", _headers.pop("Content-Type", "application/xml"))
cls: ClsType[None] = kwargs.pop("cls", None)

_file_content_type = None
Expand All @@ -187,6 +208,7 @@ async def create(
_file_content_type = file_http_headers.file_content_type
if lease_access_conditions is not None:
_lease_id = lease_access_conditions.lease_id
_content = optionalbody

_request = build_create_request(
url=self._config.url,
Expand All @@ -211,10 +233,15 @@ async def create(
group=group,
file_mode=file_mode,
nfs_file_type=nfs_file_type,
content_md5=content_md5,
file_property_semantics=file_property_semantics,
content_length=content_length,
allow_trailing_dot=self._config.allow_trailing_dot,
file_request_intent=self._config.file_request_intent,
file_type_constant=file_type_constant,
content_type=content_type,
version=self._config.version,
content=_content,
headers=_headers,
params=_params,
)
Expand Down Expand Up @@ -262,6 +289,8 @@ async def create(
response_headers["x-ms-owner"] = self._deserialize("str", response.headers.get("x-ms-owner"))
response_headers["x-ms-group"] = self._deserialize("str", response.headers.get("x-ms-group"))
response_headers["x-ms-file-file-type"] = self._deserialize("str", response.headers.get("x-ms-file-file-type"))
response_headers["Content-MD5"] = self._deserialize("bytearray", response.headers.get("Content-MD5"))
response_headers["Content-Length"] = self._deserialize("int", response.headers.get("Content-Length"))

if cls:
return cls(pipeline_response, None, response_headers) # type: ignore
Expand Down
Loading
Loading