Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@GerardSmit
Copy link
Contributor

This PR adds the following method to ICloudConvertAPI:

interface ICloudConvertAPI
{
	Task<string> UploadAsync(string url, Stream file, string fileName, object parameters);
}

Currently it's only possible to send a byte-array. Because of this, you have to load the file into memory before sending it to CloudConvert. This is fine for small files but loading large files could be a memory problem.

It's noteworthy that the stream doesn't get disposed by the API, so for example:

var stream = File.Open("file.png", FileMode.Open, FileAccess.Read, FileShare.Read);

await cloudConvertApi.UploadAsync(url, stream, "file.png", parameters);

In this example the stream is still open. You'll have to Dispose the stream yourself (or use using var stream = ...).

Tests
I've added an internal constructor in RestHelper and made the internals visible to the Tests-project. This is so I can mock the HTTP-client and check if the stream doesn't get disposed by CloudConvertAPI.

@GerardSmit GerardSmit force-pushed the feature/upload-stream branch from 4c46c4a to e315650 Compare January 2, 2023 12:05
@GerardSmit
Copy link
Contributor Author

Should I remove the integration test for stream? It seems like having 3 target frameworks and 2 separate tests for byte-array and stream is too much (6 API requests in total). The unit test fails with:

{"message":"You have started too many jobs at once","code":"PARALLEL_JOB_LIMIT_EXCEEDED"}

@josiasmontag
Copy link
Contributor

I just cleaned up that queue and tests went through now.

Looks great, thanks a lot! Could you also update the README here to use a stream instead of a byte array? (including Dispose)

@GerardSmit
Copy link
Contributor Author

Done. The preview can be viewed at https://github.com/GerardSmit/cloudconvert-dotnet/tree/feature/upload-stream#uploading-files.

@josiasmontag josiasmontag merged commit 74693ff into cloudconvert:master Jan 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants