Sending pdf as multipart/form-data via pub.client.http method

You’re on the right track. You create the multipart/form-data with the steps in your screen shot.

createMimeData -- set subType = form-data
You likely do not need to call addMimeHeader -- what are the inputs being set?
addBodyPart -- for the file; set these:
  content - the stream of the file content
  isEnvStream - no
  mimeHeader -
    Content-Disposition = form-data; name="upload" filename="%/yourVarWithFilenameNoPath%"
  contenttype - application/octet-stream; name="%/yourVarWithFilenameNoPath%" -- might specify application/pdf instead
  encoding - binary
  getEnvelopeStream -- set createMultipart = yes

http -- Nothing special needed here, just map the envStream to data/mimeStream; you could set Transfer-Encoding to chunked for efficiency

I see that the file is being read via FTP and is being loaded completely into memory. Are you sure you want to do that? You might consider a bit more modularity by:

  • Split the FTP steps to another service. Retrieve the file via FTP and store locally, temporarily.
  • Split the MIME stream creation to another service. Load the local file as a stream, not as bytes – don’t load the entire thing into memory. Pass that stream as the content to the addBodyPart call.

Splitting things up helps greatly with testing the individual major steps.

HTH.

1 Like