11

Possible Duplicate:
How can you encode to Base64 using Javascript?

I have a web application based on Java, Wicket and JQuery which has a function to enable users to upload files (images, pdfs, rtf) through multipart/form-data.

Our web security infrastructure does filtering of all http traffic to pick up possibly malicious content e.g. XSS attacks, SQL injection, buffer overruns etc

The filter doesn't distinguish between normal text input fields and file data so it picks up false positives from many uploaded binary files, preventing those files from being uploaded. I cannot change the security policy.

It seems the best way around this would be for file data to be base-64 encoded so that it is sent with a Content-Transfer-Encoding:base64 similar to what email clients do.

Is there any way to direct the browser to transfer binary as base64 or some other non-binary format?

If not, could it be done manually with some JavaScript?

Community
  • 1
  • 1
David
  • 201
  • 1
  • 2
  • 5
  • 8
    Why was my question closed as a duplicate? I did not ask "How can you do base64 encoding with JavaScript". I asked if there was a way for binary form data to be encoded in **some character format e.g base64** in the context of a form submission, whether automatically or assisted with some JavaScript. I have not found this question addressed elsewhere on stackoverflow. – David Jun 25 '12 at 05:05
  • 4
    I agree, it wasn't an exact duplicate. – biziclop Jun 25 '12 at 09:49

1 Answers1

4

It seems that you can set Content-Transfer-Encoding: base64
quote from W3C:

Each part may be encoded and the "Content-Transfer-Encoding" header supplied if the value of that part does not conform to the default (7BIT) encoding

http://www.w3.org/TR/html401/interact/forms.html#h-17.13.4.2

Provided your Java Web Server in use doesn't ingore parameter Content-Transfer-Encoding.

didxga
  • 5,935
  • 4
  • 43
  • 58
  • 2
    I think the presence of `Content-Transfer-Encoding: base64' would indicate to the server that the browser has indeed converted the binary data to base64 for transport. It's not set by the developer but is how the browser responds to the file input tag. But how can the browser be made to do the base64 encoding? – David Jun 22 '12 at 08:08
  • 3
    or you may do base64 encoding yourself, there are few jQuery plugins out there: https://github.com/carlo/jquery-base64 – didxga Jun 22 '12 at 08:21