Skip to content

[V6] [letters.create] Trouble uploading PDF #211

@kdonovan

Description

@kdonovan

I'm migrating from V5 to V6, and I'm having trouble uploading a PDF for the letters.create endpoint.

Specifically, when I pass in File.open("path-to-file.pdf") to the file argument of Lob::LetterEditable.new, the generated thumbnails in the Lob dashboard do add a page for the PDF, but it only contains a # character (see screenshot below).

Alternatives I have tried:

  • Passing just the local filename (not opening the file) -- yields "file must be a valid PDF or HTML file" (Lob::ApiError)
  • Passing File.read rather than File.open -- yields "source sequence is illegal/malformed utf-8" (JSON::GeneratorError)
    • (I also unsuccessfully tried various squish-to-valid-encodings methods from Ruby, but that doesn't feel like the right path)
  • Passing a variety of different input PDFs

Here is a minimal reproduction (just need to set LOB_API_KEY and ADDRESS_ID env vars):

#!/usr/bin/env ruby
require "lob"

config = Lob::Configuration.default
config.username = ENV.fetch("LOB_API_KEY")

api_client = Lob::ApiClient.new(config)
lob_letters = Lob::LettersApi.new(api_client)

pdf = File.open("tmp/input.pdf")

begin
  letter = Lob::LetterEditable.new({
    file: pdf,
    from: ENV.fetch("ADDRESS_ID"),
    to: ENV.fetch("ADDRESS_ID"),
    color: false,
    address_placement: "insert_blank_page",
    description: "Manual test script - PDF attachment issues"
  })

  puts lob_letters.create(letter).inspect
ensure
  pdf.close
end

And regardless of what file I use as tmp/input.pdf, this is the output in the Lob dashboard:

Screenshot 2023-03-02 at 9 51 59 AM

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions