我正在将文件上传到服务器.文件上载HTML表单有2个字段:
提交表单时,将正确接收文件内容.但是,当读取文件名(上面的第1点)时,它会出现乱码.ASCII字符正确显示.如果用其他语言(德语,法语等)给出名称,则存在问题.
在servlet方法中,请求的字符编码设置为UTF-8.我甚至尝试过如上所述的过滤器 - 如何让这段代码提交一个带有jQuery/Ajax工作的UTF-8表单textarea? - 但它似乎不起作用.只有文件名似乎是乱码.
文件名所在的MySQL表支持UTF-8.我给了随机的非英文字符,它们被正确存储/显示.
使用Fiddler,我监视请求并正确传递所有POST数据.我正在尝试确定数据如何/在哪里出现乱码.任何帮助将不胜感激.
I have to upload a file from my site yet cnt seem to get it working with drop wizard.
Here is the form from my site.
<form enctype="multipart/form-data" method="POST" action="UploadFile">
<input type="file" id="fileUpload" name="file"/>
<input type="hidden" id="fileName" name="fileName"/>
<input type="submit" value="Upload"/>
</form>
Run Code Online (Sandbox Code Playgroud)
How would I go about on the backend to receive the file?
The solution was
@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response uploadFile(
@FormDataParam("file") final InputStream fileInputStream,
@FormDataParam("file") final FormDataContentDisposition contentDispositionHeader) {
String filePath = uploadLocation + newFileName;
saveFile(fileInputStream, filePath);
String …Run Code Online (Sandbox Code Playgroud)