diff --git a/src/AssemblyAI.IntegrationTests/FilesClientTests.cs b/src/AssemblyAI.IntegrationTests/FilesClientTests.cs index 3e89ac5..1444fa1 100644 --- a/src/AssemblyAI.IntegrationTests/FilesClientTests.cs +++ b/src/AssemblyAI.IntegrationTests/FilesClientTests.cs @@ -51,4 +51,36 @@ public async Task Should_Upload_File_Using_Stream_With_Dispose() Assert.That(uploadedFile.UploadUrl, Is.Not.Null); Assert.Throws(() => fileStream.ReadByte()); } + + [Test] + public async Task Should_Upload_File_Using_ByteArray() + { + // Assuming there's a method to create a configured RawClient instance + var client = Helpers.CreateClient(); + + // Adjust the path to where your test file is located + var testFilePath = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestData", "nbc.mp3"); + var fileMemory = File.ReadAllBytes(testFilePath); + + var uploadedFile = await client.Files.UploadAsync(fileMemory).ConfigureAwait(false); + + Assert.That(uploadedFile, Is.Not.Null); + Assert.That(uploadedFile.UploadUrl, Is.Not.Null); + } + + [Test] + public async Task Should_Upload_File_Using_Memory() + { + // Assuming there's a method to create a configured RawClient instance + var client = Helpers.CreateClient(); + + // Adjust the path to where your test file is located + var testFilePath = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestData", "nbc.mp3"); + var fileMemory = new ReadOnlyMemory(File.ReadAllBytes(testFilePath)); + + var uploadedFile = await client.Files.UploadAsync(fileMemory).ConfigureAwait(false); + + Assert.That(uploadedFile, Is.Not.Null); + Assert.That(uploadedFile.UploadUrl, Is.Not.Null); + } } \ No newline at end of file diff --git a/src/AssemblyAI/Files/ExtendedFilesClient.cs b/src/AssemblyAI/Files/ExtendedFilesClient.cs index 6a37b3e..8225569 100644 --- a/src/AssemblyAI/Files/ExtendedFilesClient.cs +++ b/src/AssemblyAI/Files/ExtendedFilesClient.cs @@ -47,6 +47,54 @@ public async Task UploadAsync( await using (stream) #else using (stream) +#endif + { + return await UploadAsync(stream, options, cancellationToken).ConfigureAwait(false); + } + } + + /// + /// Upload a media file to AssemblyAI's servers. + /// + /// The audio file to upload + /// The HTTP request options + /// + /// File uploaded to AssemblyAI + public async Task UploadAsync( + ReadOnlyMemory audioFile, + RequestOptions? options = null, + CancellationToken cancellationToken = default + ) + { + var stream = new MemoryStream(audioFile.ToArray()); +#if NET6_0_OR_GREATER + await using (stream) +#else + using (stream) +#endif + { + return await UploadAsync(stream, options, cancellationToken).ConfigureAwait(false); + } + } + + /// + /// Upload a media file to AssemblyAI's servers. + /// + /// The audio file to upload + /// The HTTP request options + /// + /// File uploaded to AssemblyAI + public async Task UploadAsync( + byte[] audioFile, + RequestOptions? options = null, + CancellationToken cancellationToken = default + ) + { + var stream = new MemoryStream(audioFile); +#if NET6_0_OR_GREATER + await using (stream) +#else + using (stream) #endif { return await UploadAsync(stream, options, cancellationToken).ConfigureAwait(false);