Skip to content

Commit 427437d

Browse files
authored
Update README.md
1 parent eca1ee6 commit 427437d

1 file changed

Lines changed: 35 additions & 13 deletions

File tree

README.md

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -66,28 +66,50 @@ using (var client = new WebClient()) client.DownloadFile(fileExport.Url, fileExp
6666
```
6767

6868
## Uploading Files
69+
Uploads to CloudConvert are done via `import/upload` tasks (see the [docs](https://cloudconvert.com/api/v2/import#import-upload-tasks)). This SDK offers a convenient upload method.
6970

70-
Uploads to CloudConvert are done via `import/upload` tasks (see the [docs](https://cloudconvert.com/api/v2/import#import-upload-tasks)). This SDK offers a convenient upload method:
71+
First create the upload job with `CreateJobAsync`:
7172

7273
```c#
7374
var job = await _cloudConvertAPI.CreateJobAsync(new JobCreateRequest
7475
{
75-
Tasks = new
76-
{
77-
upload_my_file = new ImportUploadCreateRequest()
78-
// ...
79-
}
76+
Tasks = new
77+
{
78+
upload_my_file = new ImportUploadCreateRequest()
79+
// ...
80+
}
8081
});
8182

8283
var uploadTask = job.Data.Tasks.FirstOrDefault(t => t.Name == "upload_my_file");
83-
84-
var path = @"TestFiles/test.pdf";
85-
byte[] file = await File.ReadAllBytesAsync(path);
86-
string fileName = "test.pdf";
87-
88-
await _cloudConvertAPI.UploadAsync(uploadTask.Result.Form.Url.ToString(), file, fileName, uploadTask.Result.Form.Parameters);
8984
```
9085

86+
Then upload the file the file with `UploadAsync`. This can be done two ways:
87+
88+
1. **Upload using a Stream**
89+
The file will be opened and send in chunks to CloudConvert.
90+
91+
> **Note**
92+
> The stream will not be disposed. Make sure to dispose the stream with `stream.Dispose()` or by using the [using-statement](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/using-statement) as shown in the following example.
93+
```cs
94+
string path = @"TestFiles/test.pdf";
95+
string fileName = "test.pdf";
96+
97+
using (System.IO.Stream stream = await File.ReadAllBytesAsync(path))
98+
{
99+
await _cloudConvertAPI.UploadAsync(uploadTask.Result.Form.Url.ToString(), stream, fileName, uploadTask.Result.Form.Parameters);
100+
}
101+
```
102+
103+
2. **Upload using a byte-array (`byte[]`)**
104+
The entire file will be load into memory and send to CloudConvert.
105+
```cs
106+
string path = @"TestFiles/test.pdf";
107+
byte[] file = await File.ReadAllBytesAsync(path);
108+
string fileName = "test.pdf";
109+
110+
await _cloudConvertAPI.UploadAsync(uploadTask.Result.Form.Url.ToString(), file, fileName, uploadTask.Result.Form.Parameters);
111+
```
112+
91113
## Conversion Specific Options
92114

93115
You can pass any custom options to the task payload via the special `Options` property:
@@ -176,4 +198,4 @@ By default, this runs the integration tests against the Sandbox API with an offi
176198
## Resources
177199

178200
- [API v2 Documentation](https://cloudconvert.com/api/v2)
179-
- [CloudConvert Blog](https://cloudconvert.com/blog)
201+
- [CloudConvert Blog](https://cloudconvert.com/blog)

0 commit comments

Comments
 (0)