File size: 4,793 Bytes
9b76a89 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 | # coding=utf-8
# --------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
#
# Code generated by Microsoft (R) AutoRest Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is
# regenerated.
# --------------------------------------------------------------------------
from msrest.pipeline import ClientRawResponse
from .. import models
class Formdata(object):
def __init__(self, client, config, serializer, deserializer):
self._client = client
self._serialize = serializer
self._deserialize = deserializer
self.config = config
def upload_file(
self, file_content, file_name, custom_headers={}, raw=False, callback=None, **operation_config):
"""
Upload file
:param file_content: File to upload.
:type file_content: object
:param file_name: File name to upload. Name has to be spelled exactly
as written here.
:type file_name: str
:param dict custom_headers: headers that will be added to the request
:param boolean raw: returns the direct response alongside the
deserialized response
:param callback: if provided, the runtime will call the callback while
streaming upload/download. If streaming upload, response kwarg will
be None
:type callback: Callable[[concurrent.futures.Future], None] or None
:rtype: object or (object, requests.response) or
concurrent.futures.Future
"""
# Construct URL
url = '/formdata/stream/uploadfile'
# Construct parameters
query_parameters = {}
# Construct headers
header_parameters = {}
header_parameters['Content-Type'] = 'multipart/form-data'
if custom_headers:
header_parameters.update(custom_headers)
# Construct form data
form_data_content = {
'fileContent': file_content,
'fileName': file_name,
}
# Construct and send request
request = self._client.post(url, query_parameters)
response = self._client.send_formdata(
request, header_parameters, form_data_content, **operation_config)
if response.status_code not in [200]:
raise models.ErrorException(self._deserialize, response)
deserialized = None
if response.status_code == 200:
deserialized = self._client.stream_download(response, callback)
if raw:
client_raw_response = ClientRawResponse(deserialized, response)
return client_raw_response
return deserialized
def upload_file_via_body(
self, file_content, file_name, custom_headers={}, raw=False, callback=None, **operation_config):
"""
Upload file
:param file_content: File to upload.
:type file_content: object
:param file_name: File name to upload. Name has to be spelled exactly
as written here.
:type file_name: str
:param dict custom_headers: headers that will be added to the request
:param boolean raw: returns the direct response alongside the
deserialized response
:param callback: if provided, the runtime will call the callback while
streaming upload/download. If streaming upload, response kwarg will
be None
:type callback: Callable[[concurrent.futures.Future], None] or None
:rtype: object or (object, requests.response) or
concurrent.futures.Future
"""
# Construct URL
url = '/formdata/stream/uploadfile'
# Construct parameters
query_parameters = {}
# Construct headers
header_parameters = {}
header_parameters['Content-Type'] = 'application/octet-stream'
if custom_headers:
header_parameters.update(custom_headers)
# Construct body
body_content = self._client.stream_upload(file_content, callback)
# Construct and send request
request = self._client.put(url, query_parameters)
response = self._client.send(
request, header_parameters, body_content, **operation_config)
if response.status_code not in [200]:
raise models.ErrorException(self._deserialize, response)
deserialized = None
if response.status_code == 200:
deserialized = self._client.stream_download(response, callback)
if raw:
client_raw_response = ClientRawResponse(deserialized, response)
return client_raw_response
return deserialized
|