FileReference.upload fails to post multipart form with additional unicode parameters properly

1k Views Asked by At

I am in a Flex 4.0 project attempting to POST to a Java servlet using FileReference.upload(). I am sending some additional parameters such as album name in the POST. This works fine when the characters are in the Latin1 character set. When I try to post a Japanese character or some Unicode character, it doesn't come through on the Java side.

FileReference.upload() ignores the content-type setting and uses a Content-Type of multipart/form-data by default. I do not know what the default encoding is in this case. It appears that it is not UTF-8.

On the java side, httpServletRequest.getCharacterEncoding() shows null. The method is POST but I can't confirm how the data is being encoded.

So the problem is that I seem to be stuck using FileReference.upload() because the user is picking the file to upload. I need to send Unicode but I can't get Flash to encode them properly. Not sure if using URLLoader would help or if I can even get the data out of FileReference into URLLoader (and then lose progress events).

2

There are 2 best solutions below

0
On

So the answer had to do with the Java side and not the Flex side. I had to add URIEncoding="UTF-8" in my Tomcat server.xml to my connector for ports 8080 and 8443. That is what was needed to pass the unicode values. Then I had to ensure my datasource (SQL Server) was set to use sendStringParametersAsUnicode=true. Now I am able to post unicode from the Flex app to the Java app and save it in the database.

0
On

There is no need to deal with server.xml. All you need to do is to set requests character set to UTF-8 in the servlet.

request.setCharacterEncoding("UTF-8");