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;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.UncheckedIOException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.Optional;
import javax.servlet.http.HttpServletResponse;
import org.slf4j.Logger;
......@@ -99,11 +101,13 @@ public class GetFileController extends FileController {
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.setCharacterEncoding("UTF-8");
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;
while ((read = is.read(bytes)) != -1) {
out.write(bytes, 0, read);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment