Skip to content

Commit e2652f1

Browse files
committed
update C# samples
1 parent c077d00 commit e2652f1

File tree

2 files changed

+34
-0
lines changed
  • samples/client/petstore/csharp/unityWebRequest

2 files changed

+34
-0
lines changed

samples/client/petstore/csharp/unityWebRequest/net9/Petstore/src/Org.OpenAPITools/Client/ApiClient.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,23 @@ private UnityWebRequest NewRequest<T>(
282282
request = UnityWebRequest.Post(uri, form);
283283
request.method = method;
284284
}
285+
else if (contentType == "application/octet-stream")
286+
{
287+
if(options.Data is Stream stream)
288+
{
289+
using (var binaryReader = new BinaryReader(stream))
290+
{
291+
var bytes = binaryReader.ReadBytes((int)stream.Length);
292+
request = UnityWebRequest.Put(uri, bytes);
293+
request.method = method;
294+
request.SetRequestHeader("Content-Type", "application/octet-stream");
295+
}
296+
}
297+
else
298+
{
299+
throw new InvalidDataException($"{nameof(options.Data)} is not of {nameof(Stream)} type");
300+
}
301+
}
285302
else if (options.Data != null)
286303
{
287304
var serializer = new CustomJsonCodec(SerializerSettings, configuration);

samples/client/petstore/csharp/unityWebRequest/standard2.0/Petstore/src/Org.OpenAPITools/Client/ApiClient.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,23 @@ private UnityWebRequest NewRequest<T>(
282282
request = UnityWebRequest.Post(uri, form);
283283
request.method = method;
284284
}
285+
else if (contentType == "application/octet-stream")
286+
{
287+
if(options.Data is Stream stream)
288+
{
289+
using (var binaryReader = new BinaryReader(stream))
290+
{
291+
var bytes = binaryReader.ReadBytes((int)stream.Length);
292+
request = UnityWebRequest.Put(uri, bytes);
293+
request.method = method;
294+
request.SetRequestHeader("Content-Type", "application/octet-stream");
295+
}
296+
}
297+
else
298+
{
299+
throw new InvalidDataException($"{nameof(options.Data)} is not of {nameof(Stream)} type");
300+
}
301+
}
285302
else if (options.Data != null)
286303
{
287304
var serializer = new CustomJsonCodec(SerializerSettings, configuration);

0 commit comments

Comments
 (0)