Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatic transfer-decoding of file content for multipart-params #260

Open
dmichulke opened this issue Sep 21, 2016 · 2 comments
Open

Automatic transfer-decoding of file content for multipart-params #260

dmichulke opened this issue Sep 21, 2016 · 2 comments

Comments

@dmichulke
Copy link

dmichulke commented Sep 21, 2016

When receiving a file via multipart-params, there is an (optional) key
"Content-Transfer-Encoding" with values 7bit (default), 8bit, binary and base64.

Depending on these values, the file or byte array (depending on the store used) should automatically be decoded to its original form.

Using Java7 or higher, one can use (.decode (java.util.Base64/getDecoder) bytes) to receive a new byte array with the real payload.

This is an issue because upon receiving the data, the multpart-params middleware has the "Content-Transfer-Encoding" parameters available to select the correct decoding mechanism. But since the Content-Transfer-Encoding value is not transmitted further down the line, the actual consumer of the file has to guess the real Content-Transfer-Encoding.

@dmichulke
Copy link
Author

dmichulke commented Sep 21, 2016

As a current workaround for guessing whether the data is still base64 encoded I use

(if (every? #(<= (int \+) % (int \z)) (seq bytes))
    (.decode (Base64/getDecoder) bytes)
    bytes)

@dmichulke
Copy link
Author

dmichulke commented Sep 23, 2016

In a related stack overflow post, there is a discussion as to whether this is a bug in the software (PHP in this case) or in the RFC:

http://stackoverflow.com/questions/5169434/content-transfer-encoding-in-file-uploading-request#5487532

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants
@weavejester @dmichulke and others