-
-
Notifications
You must be signed in to change notification settings - Fork 7.4k
Closed
Closed
Copy link
Labels
Description
Is your feature request related to a problem? Please describe.
I think it will be beneficial to add support Stream (application/octet-stream) for unityWebRequest library, since unityWebRequest already supports sending such type of content. This will allow send data files, zips or other types of data that could not be represented as JSON.
Describe the solution you'd like
Add handling for application/octet-stream content type to csharp/libraries/unityWebRequest/ApiClient.mustache
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");
}
}Link showing how it should be done.
Describe alternatives you've considered
I considered using JsonConvertor specific for Streams, but reading Stream to string each time sending request seems to be overhead and converting from string is really weird.