【发布时间】:2011-06-07 12:42:47
【问题描述】:
当我尝试上传文件名具有瑞典字符 Ӧ Ӓ å 的文件时,我遇到了编码问题(我猜)。当我在 Windows 上而不是在 Mac OS 上上传文件时,Applet 工作正常。
在服务器端(Domino 服务器)上打印文件名时文件名变得混乱,并在 Mac 上显示框,但是当我将编码设置为 UTF-8 时 new String(filename.getBytes("utf-8")) 它在 Win 和马克。
更新:
以下是sn-ps的代码:
设置请求参数并发布
...
request.setParameter("Name", tmpAtt.getFileName());
...
HttpURLConnection connection ...
connection.setRequestProperty("Content-Type", "multipart/form-data; charset=UTF-8; boundary=" + boundary);
if (os == null) os = connection.getOutputStream();
设置文件名和输入流参数
request.setParameter(fileUploadFieldName, tmpAtt.getFilePath(), fi);
public void setParameter(String name, String filename, InputStream is) throws IOException {
boundary();
writeName(name);
write("; charset=utf-8; filename=\"");
write(filename);
write('"');
newline();
write("Content-Type:");
String type = connection.guessContentTypeFromName(filename);
if (type == null) type = "application/octet-stream";
writeln(type);
newline();
pipe(is, os);
newline();
}
最后发布到服务器
public InputStream post() throws IOException {
boundary();
writeln("--");
printOS(os);
os.close();
InputStream iis = connection.getInputStream();
printIS(iis);
return iis;
}
在 OutputStream 上写入字节以发送请求时获取此输出。我觉得名字很好。
------------------------------hxre3intl6yy-17eufpccwtxc89pbvyg0iwe3i
Content-Disposition: form-data; name="Name
Räpörå.log
------------------------------hxre3intl6yy-17eufpccwtxc89pbvyg0iwe3i
Content-Disposition: form-data; name="Name2
------------------------------hxre3intl6yy-17eufpccwtxc89pbvyg0iwe3i
Content-Disposition: form-data; name="APPROVALSTATUS
可能是什么问题。
谢谢。
【问题讨论】:
标签: java encoding applet lotus-domino osx-leopard