Revision history [back]

click to hide/show revision 1
initial version

asked 2015-07-06 09:13:52 +0800

xcapdevila gravatar image xcapdevila

Button upload loses charset

Hi all,

I'm using zk 7 and I can't encode an uploaded csv file.

When I upload the file I get ? on special characters. Default encoding is set to UTF-8 and it's working fine when the file is encoded that way but when the file has no enconding I can't force it to UTF-8 because when I get the stream or byte array the ? are already there...

I've tried taking it as text:

<z:button label="${msg.backend.actions.upload}" upload="true,maxsize=-1,multiple=false"
                    onUpload="@command('upload')" />

and as native:

<z:button label="${msg.backend.actions.upload}" upload="true,maxsize=-1,multiple=false,**native**"
                    onUpload="@command('upload')" />

but I always get the same result: ? on special characters.

Java code:

(in = media.getByteData())

String utf8Data = new String(in, Charsets.UTF_8);

StringBuilder sb = new StringBuilder();
char[] buffer = new char[4096];
InputStreamReader reader = new InputStreamReader(new ByteArrayInputStream(in), Charsets.UTF_8);
int charsRead;
while ((charsRead = reader.read(buffer)) != -1) {
 sb.append(buffer, 0, charsRead);
}
String utf8Data2 = new String(sb.toString().getBytes(Charsets.UTF_8));

Any ideas?

Many thanks.

Button upload loses charset

Hi all,

I'm using zk 7 and I can't encode an uploaded csv file.

When I upload the file I get ? on special characters. Default encoding is set to UTF-8 and it's working fine when the file is encoded that way but when the file has no enconding I can't force it to UTF-8 because when I get the stream or byte array the ? are already there...

I've tried taking it as text:

<z:button label="${msg.backend.actions.upload}" upload="true,maxsize=-1,multiple=false"
                    onUpload="@command('upload')" />

and as native:

<z:button label="${msg.backend.actions.upload}" upload="true,maxsize=-1,multiple=false,**native**"
upload="true,maxsize=-1,multiple=false,native"
                    onUpload="@command('upload')" />

but I always get the same result: ? on special characters.

Java code:

(in = media.getByteData())

String utf8Data = new String(in, Charsets.UTF_8);

StringBuilder sb = new StringBuilder();
char[] buffer = new char[4096];
InputStreamReader reader = new InputStreamReader(new ByteArrayInputStream(in), Charsets.UTF_8);
int charsRead;
while ((charsRead = reader.read(buffer)) != -1) {
 sb.append(buffer, 0, charsRead);
}
String utf8Data2 = new String(sb.toString().getBytes(Charsets.UTF_8));

Any ideas?

Many thanks.

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More