Fix CreateGuildAsync not sending icon stream. (#768)
* Fix CreateGuildAsync not doing anything with the input stream for the guild icon. Also fixes an issue with potential stream types that throw a NotSupportedException when checking its properties. [Apparently, they exist.](https://github.com/dotnet/corefx/blob/master/src/System.Net.Http.WinHttpHandler/src/System/Net/Http/WinHttpResponseStream.cs) * Merged with old method * Removed duplicate decl
This commit is contained in:
committed by
RogueException
parent
506a6c96c9
commit
865080add9
@@ -120,6 +120,9 @@ namespace Discord.Rest
|
||||
string name, IVoiceRegion region, Stream jpegIcon, RequestOptions options)
|
||||
{
|
||||
var args = new CreateGuildParams(name, region.Id);
|
||||
if (jpegIcon != null)
|
||||
args.Icon = new API.Image(jpegIcon);
|
||||
|
||||
var model = await client.ApiClient.CreateGuildAsync(args, options).ConfigureAwait(false);
|
||||
return RestGuild.Create(client, model);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System;
|
||||
using System.IO;
|
||||
using Newtonsoft.Json;
|
||||
using Model = Discord.API.Image;
|
||||
|
||||
namespace Discord.Net.Converters
|
||||
@@ -23,10 +24,24 @@ namespace Discord.Net.Converters
|
||||
|
||||
if (image.Stream != null)
|
||||
{
|
||||
byte[] bytes = new byte[image.Stream.Length - image.Stream.Position];
|
||||
image.Stream.Read(bytes, 0, bytes.Length);
|
||||
byte[] bytes;
|
||||
int length;
|
||||
if (image.Stream.CanSeek)
|
||||
{
|
||||
bytes = new byte[image.Stream.Length - image.Stream.Position];
|
||||
length = image.Stream.Read(bytes, 0, bytes.Length);
|
||||
}
|
||||
else
|
||||
{
|
||||
var cloneStream = new MemoryStream();
|
||||
image.Stream.CopyTo(cloneStream);
|
||||
bytes = new byte[cloneStream.Length];
|
||||
cloneStream.Position = 0;
|
||||
cloneStream.Read(bytes, 0, bytes.Length);
|
||||
length = (int)cloneStream.Length;
|
||||
}
|
||||
|
||||
string base64 = Convert.ToBase64String(bytes);
|
||||
string base64 = Convert.ToBase64String(bytes, 0, length);
|
||||
writer.WriteValue($"data:image/jpeg;base64,{base64}");
|
||||
}
|
||||
else if (image.Hash != null)
|
||||
|
||||
Reference in New Issue
Block a user