Skip to content
Snippets Groups Projects
Commit 7fd1ed2f authored by Sonia Zorba's avatar Sonia Zorba
Browse files

Fixed encoding issue in file download

parent f7559c36
No related branches found
No related tags found
No related merge requests found
Pipeline #1046 passed
...@@ -9,6 +9,8 @@ import java.io.IOException; ...@@ -9,6 +9,8 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.io.UncheckedIOException; import java.io.UncheckedIOException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.Optional; import java.util.Optional;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import org.slf4j.Logger; import org.slf4j.Logger;
...@@ -99,11 +101,13 @@ public class GetFileController extends FileController { ...@@ -99,11 +101,13 @@ public class GetFileController extends FileController {
String vosName = fileInfo.getVirtualPath().substring(fileInfo.getVirtualPath().lastIndexOf("/") + 1); String vosName = fileInfo.getVirtualPath().substring(fileInfo.getVirtualPath().lastIndexOf("/") + 1);
response.setHeader("Content-Disposition", "attachment; filename=" + vosName); response.setHeader("Content-Disposition", "attachment; filename=" + URLEncoder.encode(vosName, StandardCharsets.UTF_8));
response.setHeader("Content-Length", String.valueOf(file.length())); response.setHeader("Content-Length", String.valueOf(file.length()));
response.setCharacterEncoding("UTF-8");
byte[] bytes = new byte[1024]; byte[] bytes = new byte[1024];
try ( OutputStream out = response.getOutputStream(); InputStream is = new FileInputStream(file)) { try (OutputStream out = response.getOutputStream();
InputStream is = new FileInputStream(file)) {
int read; int read;
while ((read = is.read(bytes)) != -1) { while ((read = is.read(bytes)) != -1) {
out.write(bytes, 0, read); out.write(bytes, 0, read);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment