Home > Net >  ServiceStack - Post Files Async using JsonServiceClient
ServiceStack - Post Files Async using JsonServiceClient

Time:05-28

I've trying to POST a single file from one service to another as a stream using an IServiceClient (I'm using the JsonServiceClient). I can achieve this by using code similar to:

using (IServiceClient serviceClient = new JsonServiceClient(myBaseUrl)
   serviceClient.PostFile<TResponse>(relativeOrAbsoluteUrl, fileToUpload, fileName, contentType);

I see from an old SO post that there is a JsonHttpClient that I can't seem to find anymore - gone in favour of the JsonServiceClient?. That had an equivalent async method to achieve the same thing as my code example, but I can't see any way to do this using ServiceStack in the latest version ServiceStack (6.1.x).

Is there a recommended (ServiceStack) way to do this which supports async/await, or do I need to roll my own implementation (only way I can think of doing this will be to use the HttpClient and specify a MultipartFormDataContent on the request)?

CodePudding user response:

The recommended ServiceClient for .NET 6 is to use is the JsonApiClient which has a number of APIs to Upload Files from C#.

  • Related