1

Seriously.

I've been scratching around trying to find the answer to this conundrum for a while.

The request size is too large if the String is encoded, and the company won't take Base64 anyway. They actually want the binary code, but in JSON. Can anyone shed any light on how they think that other people might do this? Currently I'm processing it like this;

    String addressProof = null;

    if (proofRequired)
    {
        Part filePart = request.getPart("proof_of_address");
        addressFileName = getSubmittedFileName(filePart);
        InputStream fileContent = filePart.getInputStream();

        final byte[] bytes = IOUtils.toByteArray(fileContent);
        addressProof = new String(bytes);
        //byte[] bytes64 = Base64.encodeBase64(fileBytes);
        //addressProof = new String(fileBytes);

        fileContent.close();
    }

Am I being dim, or is this whole request, just a little bit flawed.

Many thanks.

juju
  • 553
  • 1
  • 4
  • 21
  • 2
    *the binary code, but in JSON*: that's a contradiction. Who is "the company"? Why don't you ask "the company" how you're supposed to transfer a PDF file? – JB Nizet May 08 '17 at 11:09
  • I have already, they're intent that it's possible, but I'm not actually through to dev support, it's more app support. I'll try again I guess. – juju May 08 '17 at 11:13
  • 1
    @JBNizet yes, I was mixing concepts up, sorry. – walen May 08 '17 at 13:02

1 Answers1

0

You can send it (or receive) as a hex string. See how-to-convert-a-byte-array-to-a-hex-string-in-java.

Example output would be (if enclosed by a JSON object):

{
    "content": "C5192E4190E54F5985ED09C6CD0D4BCC"
}

or just plain hex string: "C5192E4190E54F5985ED09C6CD0D4BCC"

You don't have to write it (or read) all at once. You can open two streams (in and out) and then stream the data. From file to response output stream or from request input stream to file.

Sorry but I am not sure if You want to send the bytes or receive them.

Community
  • 1
  • 1