Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I post binary html multipart form data in a character-based encoding?

I have a web page that allows a user to upload files using multipart/form data (i.e. with an input type="file" tag). However, here is a web content security filter in my way which is effectively blocking binary form data being submitted.

Is it possible to have have binary form data converted and sent as character data (e.g base64)? Preferably this would be done automatically by the browser through a declarative instruction if that is possible. I think it is not but thought I'd ask.

Otherwise, can it be done programmatically so that some JavaScript intercepts the form submission and changes the file content uploaded with the form data?

A solution based on wicket and/or jquery is preferable.

Note: I am not asking how to do base64 encoding in JavaScript. Please do not mark this as a duplicate without actually understanding the question first as did the five people who voted to close my first attempt of the question! How to send binary multipart formdata as base64?

The question is more about how to make any such encoding take place in the context of a multipart form submission.

like image 463
David Avatar asked Jun 25 '12 09:06

David


People also ask

Is multipart form data binary?

The media type multipart/form-data is the preferred media type for request payloads that contain files, non-ASCII, and binary data. CloudStreams supports this media type using which you can embed binary data such as files into the request body in a transparent way.

What is content type multipart form data?

multipart/form-data [RFC1867] The multipart/form-data content type is intended to allow information providers to express file upload requests uniformly, and to provide a MIME-compatible representation for file upload responses.


1 Answers

OK, after some more research I'm going to call an answer on my own question.

This question on SO provides the answer indirectly though the question is not the same.

Is it possible to intercept the file from a <input type=file> in javascript?

Basically it appears there is no standard way (in HTML4 anyway, looks possible with HTML5) to access the actual content of a selected file from the browser)

Thus no re-encoding of an uploaded file can occur before it is sent to the browser.

like image 137
David Avatar answered Oct 20 '22 05:10

David