Skip to content

Commit

Permalink
optional filename arg for CreateAssetAsync with local path
Browse files Browse the repository at this point in the history
  • Loading branch information
gehongyan committed May 4, 2024
1 parent 815ea8e commit 6caa01f
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/Kook.Net.Rest/KookRestClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,16 @@ public Task RemoveDirectMessageReactionAsync(Guid messageId, ulong userId, IEmot
/// <param name="filename"> The name of the file. </param>
/// <param name="options"> The options to be used when sending the request. </param>
/// <returns> The asset resource URI of the uploaded file. </returns>
public Task<string> CreateAssetAsync(string path, string filename, RequestOptions? options = null) =>
ClientHelper.CreateAssetAsync(this, File.OpenRead(path), filename, options);
public async Task<string> CreateAssetAsync(string path, string? filename = null, RequestOptions? options = null)
{
#if NETSTANDARD2_1_OR_GREATER || NET5_0_OR_GREATER
await using FileStream fileStream = File.OpenRead(path);
#else
using FileStream fileStream = File.OpenRead(path);
#endif
return await ClientHelper.CreateAssetAsync(this, fileStream, filename ?? Path.GetFileName(path), options)
.ConfigureAwait(false);
}

/// <summary>
/// Creates an asset from a stream.
Expand Down

0 comments on commit 6caa01f

Please sign in to comment.