Skip to content

Commit

Permalink
fix-FileServer-中文文件名下载乱码问题
Browse files Browse the repository at this point in the history
  • Loading branch information
aruis committed Oct 29, 2024
1 parent 92403b0 commit 7656b64
Showing 1 changed file with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.slf4j.LoggerFactory;

import java.io.File;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;

@ApplicationScoped
Expand Down Expand Up @@ -109,10 +110,9 @@ private void download(RoutingContext ctx) {
vertx.fileSystem().readFile(nameFilePath, result -> {
if (result.succeeded()) {
Buffer buffer = result.result();
String fileName = new String(buffer.getBytes(), StandardCharsets.ISO_8859_1);
if (fileObtained.exists()) {
ctx.response()
.putHeader("Content-Disposition", "attachment; filename=" + fileName)
.putHeader("Content-Disposition", "attachment; filename*=UTF-8''" + URLEncoder.encode(buffer.toString(), StandardCharsets.UTF_8))
.putHeader("Content-type", "application/octet-stream")
.sendFile(fileObtained.getPath());
// vertx.fileSystem().delete(fileObtained.getPath());
Expand Down

0 comments on commit 7656b64

Please sign in to comment.