Skip to content

Commit c077d00

Browse files
[REQ] [CSHARP] [UNITYWEBREQUEST] Support Stream for unityWebRequest library (#21704)
* Update ApiClient.mustache * Update ApiClient.mustache
1 parent f659457 commit c077d00

File tree

1 file changed

+17
-0
lines changed
  • modules/openapi-generator/src/main/resources/csharp/libraries/unityWebRequest

1 file changed

+17
-0
lines changed

modules/openapi-generator/src/main/resources/csharp/libraries/unityWebRequest/ApiClient.mustache

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,23 @@ namespace {{packageName}}.Client
274274
request = UnityWebRequest.Post(uri, form);
275275
request.method = method;
276276
}
277+
else if (contentType == "application/octet-stream")
278+
{
279+
if(options.Data is Stream stream)
280+
{
281+
using (var binaryReader = new BinaryReader(stream))
282+
{
283+
var bytes = binaryReader.ReadBytes((int)stream.Length);
284+
request = UnityWebRequest.Put(uri, bytes);
285+
request.method = method;
286+
request.SetRequestHeader("Content-Type", "application/octet-stream");
287+
}
288+
}
289+
else
290+
{
291+
throw new InvalidDataException($"{nameof(options.Data)} is not of {nameof(Stream)} type");
292+
}
293+
}
277294
else if (options.Data != null)
278295
{
279296
var serializer = new CustomJsonCodec(SerializerSettings, configuration);

0 commit comments

Comments
 (0)