Skip to content

Report Files content is assumed to always be text #320

Closed
@miguel-ferreira-cko

Description

@miguel-ferreira-cko

Environment

  • Checkout SDK version: 4.0.15
  • Platform and version: .NET 7.0.203
  • Operating System and version: Windows 22H2

Description

Report File content should not always be treated as text. In some cases it can be a binary format (e.g. PDF) which cannot be encoded as a text in .NET (be it ASCII, UTF8...) and must be treated as a byte array / stream / base64 so that it can be properly stored.

Expected behavior

Report File content accurately contains the original file bytes.

Current behavior

Report File content contains a string encoding of the original file bytes, which when encoded back into binary form will be missing data.

Steps to reproduce

  1. Download the PDF file via command line (e.g. PowerShell) Invoke-RestMethod -Method Get -Uri 'https://api.checkout.com/reports/REPORT_ID/files/FILE_ID' -Headers @{"Authorization"="SECRET"} -OutFile original.pdf
  2. Download the same PDF file using the Checkout SDK and attempt to save in any of the available text encodings
using Checkout;
using System.Text;

ICheckoutApi api = CheckoutSdk.Builder().StaticKeys()
    .SecretKey("SECRET")
    .Environment(Checkout.Environment.Production)
    .Build();

var reportId = "REPORT ID WHERE .Files[0].Format == PDF";

var report = await api
    .ReportsClient()
    .GetReportDetails(reportId);

var file = await api
    .ReportsClient()
    .GetReportFile(reportId, report.Files[0].Id);

File.WriteAllBytes("report.pdf", Encoding.Unicode.GetBytes(file.Body));
File.WriteAllBytes("report2.pdf", Encoding.UTF8.GetBytes(file.Body));
File.WriteAllBytes("report3.pdf", Encoding.ASCII.GetBytes(file.Body));
File.WriteAllBytes("report4.pdf", Encoding.UTF32.GetBytes(file.Body));
File.WriteAllBytes("report5.pdf", Encoding.Latin1.GetBytes(file.Body));
File.WriteAllText("report6.pdf", file.Body, Encoding.ASCII);
  1. Observe that none of the PDF files that had their bytes text encoded previously is keeping the original file bytes:
    image

Possible solution

  • I may be able to implement this bug fix

Additional information

Metadata

Metadata

Labels

enhancementNew feature or requestquestionFurther information is requested

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions