No announcement yet.

ShareFile help encoding issue (not sure if mirth or sharefile)

  • Filter
  • Time
  • Show
Clear All
new posts

  • ShareFile help encoding issue (not sure if mirth or sharefile)

    Here is my oauth implementation. It works fine and I am trying to stream multi-part. It works but I cannot get these garbage characters out of my pdf. It works great and fine in python and php but not in mirth. Can someone take a look and enlighten me?

    I could easily use cURL but I want to know for my own knowledge. Thanks for anyone who can help..
    Attached Files
    Last edited by nafwa03; 11-30-2019, 07:02 AM. Reason: solved

  • #2
    More info

    Ok. so I have determined from more digging that I should be chunking based off of some code samples particularly this:

    // read from file, and write to outputstream
            byte[] buf = new byte[1024*1024];
            int len;
            while((len =, 0, buf.length)) >= 0) {
                target.write(buf, 0, len);
    The file sizes are the same as local and are uploaded but they are blank due to junk [] decoded as 7+7 or 77+. I have tried various encoding and all it does is increase the size of the uploaded files but still garbage. Tried on many different pdfs and some not my own. Possibly anyone can help? Before I go down the road to bundle a class jar I figured would ask. Thanks in advance.


    • #3
      Many thanks to Kirby on MultiPartEntityBuilder

      Adapted some code slightly from this post:

      Mapped contenttype to 'application/octet-stream'
      Ensure "File1" is string for first addBinaryBody argument (this is not documented well)

      var pdfContent = "C:\\users\\mirth\\Desktop\\input2.pdf";
      var filename = 'input2.pdf';
      var entity = org.apache.http.entity.mime.MultipartEntityBuilder
      .addBinaryBody("File1", FileUtil.readBytes(pdfContent), org.apache.http.entity.ContentType.create($('contentType')), $('filename')).build();
      var bos = new;
      msg = FileUtil.encode(bos.toByteArray());
      Add this to transformer step2 on destination 4. Change variables or map accordingly. Thats it. Hope this helps someone one day!