mirror of
https://gitee.com/kekingcn/file-online-preview.git
synced 2025-08-20 09:26:40 +08:00
修复FTP文件名或路径为中文无法预览的问题
This commit is contained in:
parent
6746325bf2
commit
e604379a18
@ -1,6 +1,7 @@
|
||||
package cn.keking.utils;
|
||||
|
||||
import cn.keking.config.ConfigConstants;
|
||||
import jodd.util.URLDecoder;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.net.ftp.FTPClient;
|
||||
import org.apache.commons.net.ftp.FTPReply;
|
||||
@ -44,7 +45,13 @@ public class FtpUtils {
|
||||
URL url = new URL(ftpUrl);
|
||||
String host = url.getHost();
|
||||
int port = (url.getPort() == -1) ? url.getDefaultPort() : url.getPort();
|
||||
String remoteFilePath = url.getPath();
|
||||
String path = url.getPath();
|
||||
int fileNameStartIndex = path.lastIndexOf("/");
|
||||
int fileNameLatestIndex = path.lastIndexOf(".");
|
||||
String startPath = path.substring(0, fileNameStartIndex+1);
|
||||
String endPath = path.substring(fileNameLatestIndex);
|
||||
String fileName = path.substring(fileNameStartIndex+1, fileNameLatestIndex);
|
||||
String remoteFilePath = startPath+ URLDecoder.decode(fileName, StringUtils.isEmpty(ftpControlEncoding) ? "UTF-8" : ftpControlEncoding) + endPath;
|
||||
LOGGER.debug("FTP connection url:{}, username:{}, password:{}, controlEncoding:{}, localFilePath:{}", ftpUrl, username, password, controlEncoding, localFilePath);
|
||||
FTPClient ftpClient = connect(host, port, username, password, controlEncoding);
|
||||
OutputStream outputStream = Files.newOutputStream(Paths.get(localFilePath));
|
||||
|
||||
Loading…
Reference in New Issue
Block a user