We currently use the IServiceGateway
from an MVC controller to call our API where the DTO is decorated with IRequiresRequestStream
. Subsequently we access IRequest.Files
to get the contents of the stream.
using (var stream = System.IO.File.OpenRead(fileName))
{
await base.Gateway.SendAsync(new PublicationUpload()
{
Id = publication.Id,
JobId = job.Id,
RequestStream = stream
});
}
This was working up to v6.3 but IRequest.Files
is empty with later versions. I created a test case to investigate but this uses JsonServiceClient
and not the gateway.
using (var stream = File.OpenRead(fileName))
{
var response = client.Send(new PublicationUpload
{
Id = publication.Id,
JobId = job.Id,
RequestStream = stream
});
}
I was unable to get this test to pass (asserting that IRequest.Files
is not empty) even using v6.3 but it does pass by using PostFileWithRequest
instead.
using (var stream = File.OpenRead(fileName))
{
var response = client.PostFileWithRequest<DataResponse>(stream, "test.txt", new PublicationUpload
{
Id = publication.Id,
JobId = job.Id
});
}
To update the call from our MVC controller, and allow an upgrade from v6.3, is there an equivalent method to PostFileWithRequest
available from the gateway?
Is the a good way to create a JsonServiceClient
from the controller which is configured to access the API like the gateway?