Ensure UploadFile is always a seekable stream.
This commit is contained in:
@@ -494,13 +494,8 @@ namespace Discord.API
|
||||
|
||||
if (args.Content.GetValueOrDefault(null) == null)
|
||||
args.Content = "";
|
||||
else if (args.Content.IsSpecified)
|
||||
{
|
||||
if (args.Content.Value == null)
|
||||
args.Content = "";
|
||||
if (args.Content.Value?.Length > DiscordConfig.MaxMessageSize)
|
||||
throw new ArgumentOutOfRangeException($"Message content is too long, length must be less or equal to {DiscordConfig.MaxMessageSize}.", nameof(args.Content));
|
||||
}
|
||||
else if (args.Content.IsSpecified && args.Content.Value?.Length > DiscordConfig.MaxMessageSize)
|
||||
throw new ArgumentOutOfRangeException($"Message content is too long, length must be less or equal to {DiscordConfig.MaxMessageSize}.", nameof(args.Content));
|
||||
|
||||
var ids = new BucketIds(channelId: channelId);
|
||||
return await SendMultipartAsync<Message>("POST", () => $"channels/{channelId}/messages", args.ToDictionary(), ids, clientBucket: ClientBucketType.SendEdit, options: options).ConfigureAwait(false);
|
||||
|
||||
@@ -101,7 +101,14 @@ namespace Discord.Net.Rest
|
||||
if (p.Value is MultipartFile)
|
||||
{
|
||||
var fileValue = (MultipartFile)p.Value;
|
||||
content.Add(new StreamContent(fileValue.Stream), p.Key, fileValue.Filename);
|
||||
var stream = fileValue.Stream;
|
||||
if (!stream.CanSeek)
|
||||
{
|
||||
var memoryStream = new MemoryStream();
|
||||
await stream.CopyToAsync(memoryStream).ConfigureAwait(false);
|
||||
stream = memoryStream;
|
||||
}
|
||||
content.Add(new StreamContent(stream), p.Key, fileValue.Filename);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user