Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 792
  • Last Modified:

File Upload

Hi

I got a problem when I try to upload a file using this UploadBean http://www.javazoom.net/jzservlets/uploadbean/documentation/index.html. The problem is that it is impossible to upload files with the danish characters "æøå" in Linux!

It works well under Windows but not in Linux.

Hope someone can help me.

Jan
0
COOLJMA
Asked:
COOLJMA
  • 13
  • 8
  • 5
  • +2
2 Solutions
 
thanassisCommented:
I think you are in trouble.
Have you installed danish fonts in your Linux machine?
0
 
kennethxuCommented:
it's nothing to do with the font, rather the characterset your linux supports.

do you mean the danish characters in file name or file content?

can you please post the full stacktrace of the error you get?

thanks.
0
 
COOLJMAAuthor Commented:
The characters works well under Linux but not when I use the UploadBean. I don't get an error, it just upload the file as for instance æøå.txt to ???.txt. There after its not possible to download the file again, even i you write ???.txt.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
kennethxuCommented:
that's character encoding issue. which encoding system are you using utf-8?
0
 
cheekycjCommented:
why is character encoding an issue for binary file transfers?

encoding is only an issue if you are dealing with ascii streams or strings etc.

CJ
0
 
kennethxuCommented:
CJ, COOLJMA have problem with his file name.
0
 
cheekycjCommented:
oh, I thought it was the content.

yes that is the client machine and the server machine's issue.

The client machine must support the character set and so does the server machine to store it.

CJ
0
 
kennethxuCommented:
>> The client machine must support the character set and so does the server machine to store it.
not necessary, it is possible to use different character set as long as you can convert one to the other.
0
 
cheekycjCommented:
true but I am working on a project where conversion btw Unicode and UTF-8 charactersets is causing big problems so I am not sure if thats something you want to leave to conversion anymore.

CJ
0
 
kennethxuCommented:
hmmm, what do you unicode to utf-8, utf-8 is one of unicode encoding. do you mean utf-16 to utf-8?
0
 
cheekycjCommented:
unicode 2.0 to utf-8.

the conversion has problems with high ascii characters.  I have a question open about it in the java topic area.

CJ
0
 
kennethxuCommented:
I used to be in java topic area, but just don't have enough time to run on two topics :(
I can have a look at it if you post the link.
0
 
COOLJMAAuthor Commented:
Your are probably on the right target about the encoding because the same problem raise if you have to print out something from a database. The characters is saved right in the database but is not printed right if it comes from the database. But for some weird reason it is possible to write <%="æøå"%>. And this works... the used characterset on the Linux mashine is not UTF but ISO8859-1.

Jan
0
 
kennethxuCommented:
can you show us the code of upload and download?
0
 
COOLJMAAuthor Commented:
Yes it is the default from JavaZoom on http://www.javazoom.net/jzservlets/uploadbean/uploadbean.html#download. The version is 1.3...and the JSP file is SimpleUpload.jsp
0
 
kennethxuCommented:
right, but

1. the default was "D:/uploads" for upload dir, you must have change it to work with linux.

2. what about your download page?
0
 
COOLJMAAuthor Commented:
I changed it to "/var/tomcat4/webapps/ROOT/cooljma/doc".

On my download page I just write..
<a href="doc/filename">filename</a>

But it is pretty sure that the problem is JAVA or the encoding, because if you make a System.out.println("æøå"); you will get a wrong result also in Windows. In Windows the way to solve this is by adding the parameter -Dfile.encoding=Cp850 but I have no idea how to set this by default or how to set this in Linux, and expecially not which encoding that works, because -Dfile.encoding=ISO8859-1 do not work, either do -Dfile.encoding=Cp850. Therefore im pretty lost.

Jan
0
 
kennethxuCommented:
I didn't have cp850 installed, but when I tried gb2313 (chinese coding), uploadbean changed every chinese character into &#xxxx; in filename. which works fine when i download because browser will translate it back to chinese character. strange that you are getting something different.
0
 
kennethxuCommented:
not so sure but can you try:

UploadFile file = (UploadFile) mrequest.getFiles().get( "uplaodfile" );
file.setFileName( new String( file.getFileName().getBytes("ISO8859-1"), "Cp850" );

0
 
COOLJMAAuthor Commented:
Nice try kennethxu.. you have to switch ao in uploadfile and there are missing a ")" in the last line.. but this didn't work either.. It says null pointer exception and made need for a restart of tomcat... Because it keep saying that even if I removed the 2 linies again.

Jan
0
 
COOLJMAAuthor Commented:
About the Chinese coding, this might caused by the fact that this language are supported. If I need to download the file &aelig;&oslash;&aring;.txt the filename i have to type is %3F%3F%3F.txt

Jan
0
 
kennethxuCommented:
sorry for the bad try :) i was not at my PC when I post, so didn't tested myself.

the first line of code is not needed, because SimpleUplaod.jsp already have it. I added the 2nd line to my code and purposely prefix filename with "XXXXX".

file.setFileName( "XXXXX" + new String( file.getFileName().getBytes("ISO8859-1"), "Cp850" ) );

it worked for me, and files in dir does contain "XXXXX", that mean you can rename and/or change encoding in this way.

2ndly, in jsp page you'll need to
<%@page contentType="text/html; charset=IBM850" encoding="Cp850"%>
0
 
kennethxuCommented:
sorry I didn't try the characters you mentioned, because I don't know how to enter them :(
0
 
COOLJMAAuthor Commented:
Kennethxu, did you test this in Linux or Windows?? I have found out that it might be the JRE that causes the problem because my filesystem is ISO8859-1 and my file-encoding in JRE is ANSI_X3.4-1968. I found this by running this code.

public class TestEncoding {
     public static void main(String[] args) {
     System.out.print("File.encoding: ");
     System.out.println(System.getProperty("file.encoding"));
     }
}

It seem that i'm not the only one with the problem.
http://forum.java.sun.com/thread.jsp?thread=315993&forum=16&message=14

http://developer.java.sun.com/developer/bugParade/bugs/4803820.html

Jan
0
 
kennethxuCommented:
How is this going? my LANG=en_US.UTF-8 in linux, I can only tested Chinese, it's been converted to &#xxxx; and works fine.

you can try to use java -Dfine.encoding=ISO8859-1 when you start you server, or set LANG=???.
0
 
COOLJMAAuthor Commented:
I already tried this but this is not working... I believe that it is because that Chinese is supported and Danish is not.
0
 
cheekycjCommented:
any updates here?

CJ
0
 
girionisCommented:
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

- Split points between kennethxu and cheekycj

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

girionis
EE Cleanup Volunteer
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 13
  • 8
  • 5
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now