lob/lob-ruby

[V6] [letters.create] Trouble uploading PDF

Opened this issue · 2 comments

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

Hey @kdonovan,

This is definitely a bug in our V6 release, I will add a ticket for the team to address this. I don't have a specific window for when we will be able to address it. If possible stay with V5 and I will update this comment when this issue is resolved.

Thanks!

@BennyKitchell - Any update on this one? This is 1 of the issues blocking Kali and I from upgrading to V6.