[REQ] [CSHARP] [UNITYWEBREQUEST] Support Stream for unityWebRequest library (#21704)

* Update ApiClient.mustache

* Update ApiClient.mustache
This commit is contained in:
Arcueid D`athemon 2025-08-07 03:20:11 +02:00 committed by GitHub
parent f659457f90
commit c077d005d5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -274,6 +274,23 @@ namespace {{packageName}}.Client
request = UnityWebRequest.Post(uri, form); request = UnityWebRequest.Post(uri, form);
request.method = method; request.method = method;
} }
else if (contentType == "application/octet-stream")
{
if(options.Data is Stream stream)
{
using (var binaryReader = new BinaryReader(stream))
{
var bytes = binaryReader.ReadBytes((int)stream.Length);
request = UnityWebRequest.Put(uri, bytes);
request.method = method;
request.SetRequestHeader("Content-Type", "application/octet-stream");
}
}
else
{
throw new InvalidDataException($"{nameof(options.Data)} is not of {nameof(Stream)} type");
}
}
else if (options.Data != null) else if (options.Data != null)
{ {
var serializer = new CustomJsonCodec(SerializerSettings, configuration); var serializer = new CustomJsonCodec(SerializerSettings, configuration);