Quantcast
Channel: SmartClient Forums
Viewing all articles
Browse latest Browse all 4756

Upload Form with filename in other language

$
0
0
I have an upload form which saves the uploaded contents to a database. It works fine except when the filename includes foreign characters.
In my example, "Dok1ü.doc" is uploaded as "Dok1?.doc".

When I try the example in http://www.smartclient.com/smartgwte...se/#upload_sql , the filename is displayed correctly in the listGrid.

I wrote a DMI handler to see how the string containing the filename arrives at the server:

Code:


public class DokumenteDMIHandler {

        public DSResponse doAdd(DSRequest dsRequest,
                        HttpServletRequest servletRequest) throws Exception {
                servletRequest.setCharacterEncoding("UTF-8");
                System.out.println("LOGGING: CALLING doUpdate");

                String filename = ((String) dsRequest.getClientSuppliedValues().get("f_datei"));
                byte[] utf8Bytes = filename.getBytes("UTF8");
            byte[] defaultBytes = filename.getBytes();
            byte[] isoBytes = filename.getBytes("ISO-8859-1");
            byte[] utf16Bytes = filename.getBytes("UTF16");
            byte[] windowsBytes = filename.getBytes("Windows-1252");
           
            String roundTrip = new String(utf8Bytes, "UTF8");
            System.out.println("roundTrip = " + roundTrip);
            System.out.println();
            printBytes(utf8Bytes, "utf8Bytes");
            System.out.println();
            printBytes(defaultBytes, "defaultBytes");
            System.out.println();
            printBytes(isoBytes, "isoBytes");
            System.out.println();
            printBytes(utf16Bytes, "utf16Bytes");
            System.out.println();
            printBytes(windowsBytes, "Windows-1252");
           
            String umlaut = "ü";
            byte[] umlautBytes = umlaut.getBytes("UTF8");
            System.out.println("Umlaut: " + umlaut);
            printBytes(umlautBytes, "umlaut");
               
                DSResponse response = dsRequest.execute();

                return response;

        }
       
        public static void printBytes(byte[] array, String name) {
            for (int k = 0; k < array.length; k++) {
                System.out.println(name + "[" + k + "] = " + "0x" +
                    byteToHex(array[k]));
            }
        }
       
        static public String byteToHex(byte b) {
              // Returns hex String representation of byte b
              char hexDigit[] = {
                '0', '1', '2', '3', '4', '5', '6', '7',
                '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'
              };
              char[] array = { hexDigit[(b >> 4) & 0x0f], hexDigit[b & 0x0f] };
              return new String(array);
          }
       
          static public String charToHex(char c) {
              // Returns hex String representation of char c
              byte hi = (byte) (c >>> 8);
              byte lo = (byte) (c & 0xff);
              return byteToHex(hi) + byteToHex(lo);
          }

}

The output is:
Code:

LOGGING: CALLING doUpdate
roundTrip = Dok1�.doc

utf8Bytes[0] = 0x44
utf8Bytes[1] = 0x6f
utf8Bytes[2] = 0x6b
utf8Bytes[3] = 0x31
utf8Bytes[4] = 0xef
utf8Bytes[5] = 0xbf
utf8Bytes[6] = 0xbd
utf8Bytes[7] = 0x2e
utf8Bytes[8] = 0x64
utf8Bytes[9] = 0x6f
utf8Bytes[10] = 0x63

defaultBytes[0] = 0x44
defaultBytes[1] = 0x6f
defaultBytes[2] = 0x6b
defaultBytes[3] = 0x31
defaultBytes[4] = 0xef
defaultBytes[5] = 0xbf
defaultBytes[6] = 0xbd
defaultBytes[7] = 0x2e
defaultBytes[8] = 0x64
defaultBytes[9] = 0x6f
defaultBytes[10] = 0x63

isoBytes[0] = 0x44
isoBytes[1] = 0x6f
isoBytes[2] = 0x6b
isoBytes[3] = 0x31
isoBytes[4] = 0x3f
isoBytes[5] = 0x2e
isoBytes[6] = 0x64
isoBytes[7] = 0x6f
isoBytes[8] = 0x63

utf16Bytes[0] = 0xfe
utf16Bytes[1] = 0xff
utf16Bytes[2] = 0x00
utf16Bytes[3] = 0x44
utf16Bytes[4] = 0x00
utf16Bytes[5] = 0x6f
utf16Bytes[6] = 0x00
utf16Bytes[7] = 0x6b
utf16Bytes[8] = 0x00
utf16Bytes[9] = 0x31
utf16Bytes[10] = 0xff
utf16Bytes[11] = 0xfd
utf16Bytes[12] = 0x00
utf16Bytes[13] = 0x2e
utf16Bytes[14] = 0x00
utf16Bytes[15] = 0x64
utf16Bytes[16] = 0x00
utf16Bytes[17] = 0x6f
utf16Bytes[18] = 0x00
utf16Bytes[19] = 0x63

Windows-1252[0] = 0x44
Windows-1252[1] = 0x6f
Windows-1252[2] = 0x6b
Windows-1252[3] = 0x31
Windows-1252[4] = 0x3f
Windows-1252[5] = 0x2e
Windows-1252[6] = 0x64
Windows-1252[7] = 0x6f
Windows-1252[8] = 0x63
Umlaut: ü
umlaut[0] = 0xc3
umlaut[1] = 0xbc

No encoding seems to be the correct one.

But, as I said, when trying the same file in http://www.smartclient.com/smartgwte...se/#upload_sql , everything works fine.

I read of a similar problem here:
http://stackoverflow.com/questions/5...part-form-data

My datasource:
Code:

<DataSource ID="dokumente" serverType="sql" tableName="t_dokumente"  >
        <fields>
                <field name="f_id" type="sequence" primaryKey="true" hidden="true" />
                <field name="f_beschreibung" type="text" hidden="true" />
                <field name="f_datei" type="binary" />
                <field name="f_datei_filename" type="text" hidden="true" />
               
        </fields>
       
        <operationBindings>
               
                <operationBinding operationType="add">
                        <serverObject className="zedes2.server.dmi.DokumenteDMIHandler"
                                methodName="doAdd" />
                </operationBinding>
        </operationBindings>
       
</DataSource>

For the upload I use DynamicForm, which uses a FileItem for the file upload.

My .gwt.xml contains <?xml version="1.0" encoding="UTF-8"?>. My main html page also contains: <meta http-equiv="content-type" content="text/html; charset=UTF-8">

Everywhere else (i.e. in all grids, html, etc) the foreign characters are working.

Using SmartClient Version: v9.1p_2014-03-22/PowerEdition Deployment (built 2014-03-22)

Viewing all articles
Browse latest Browse all 4756

Trending Articles