jgiacomini / Tiny.RestClient

Simpliest Fluent REST client for .NET
MIT License
210 stars 30 forks source link

AddFileContent Using MultipartFormDataStreamProvider #88

Closed aboah closed 5 years ago

aboah commented 5 years ago

Hello Please How can Developers upload files of application/octet-stream with Tiny.RestClient Using Web Api MultipartFormDataStreamProvider

Can you show us a working Example

jgiacomini commented 5 years ago

Hello,

You can do it like that =>

var response = await client.
                PostRequest("City/Image/Add").
                AsMultiPartFromDataRequest().
                AddFileContent(fileInfo1, "text/plain").
                AddFileContent(fileInfo2, "text/plain").
                ExecuteAsync<Response>();

If you prefer use byte array the syntax is :

// With 2 byte array content
byte[] byteArray1 = ...
byte[] byteArray2 = ...           

await client.PostRequest("MultiPart/Test").
              AsMultiPartFromDataRequest().
              AddByteArray(byteArray1, "request", "request2.bin").
              AddByteArray(byteArray2, "request", "request2.bin")
              ExecuteAsync();