Reputation: 89
I'm trying to consume an API that my team created that returns a FileContentResult
(a PDF File) for mobile.
I have written some code to retrieve the byte array of that result as shown below.
Line that returns PDF file in the API:
return new FileContentResult(result.Data.Data, "application/pdf");
My code:
public class QuoteCoreService : BaseService, IQuoteCoreService
{
public QuoteCoreService(IService<CollaborationClient> httpClient, IAuthenticationService authenticationService) : base(httpClient, authenticationService)
{
}
public byte[] GetSampleTag(string QuoteId)
{
var headers = BuildHeaders();
byte[] result;
try
{
result = _httpClient.Get<byte[]>("SampleTagUpdate/PDFFile/" + QuoteId, headers).Result;
}
catch(Exception e)
{
Crashes.TrackError(e, new Dictionary<string, string> { { "GetSampleTag()", "HTTP Call to service" } });
result = null;
}
return null;
}
}
IService<CollaborationClient>
is just HttpClient with some basic configs added in the background. I expect _httpClient.Get
line to return a byte array.
Upvotes: 1
Views: 1288