1

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 is just HttpClient with some basic configs added in the background. I expect _httpClient.Get line to return a byte array.

Anthony R
  • 89
  • 1
  • 10
  • you want to get the FileContents property of the return object - that is the byte[] that represents the file data. – Jason Sep 11 '19 at 16:37
  • I dont follow. Is that what im doing when I'm writing – Anthony R Sep 11 '19 at 18:26
  • no, you are taking the ENTIRE return object as a byte[]. Presumably the return object is json, so you should be able to deserialize it and extract just the FileContents – Jason Sep 11 '19 at 18:30

0 Answers0