损坏的图像上传在CPANEL中,有404错误
我在春季和角度技术的生产环境中将图像上传到FTP服务器(使用CPANEL)时有问题。 将文件上传到指定的文件夹TMP,但上传的图像已损坏,并且无法使用此错误404(找不到)显示。 当我从CPANEL手动上传相同的图像时,它可以很好地工作。 请任何命题:) 这是源代码:
public类ftpservice {
static FTPClient ftp = new FTPClient();
static String TMP_UPLOAD_FOLDER = "/home/myproject/public_html/tmp/";
static String SERVER_DOMAIN = " XX.XXX.XX.XX";
static String SERVER_USERNAME = "username1";
static String SERVER_PASSWORD = "myPassword";
public static String uFileUpload(MultipartFile file, String TypePhoto, Long clientId) throws IOException {
if (file.isEmpty()) {
System.out.println("Empty File");
return "Empty File";
} else {
// dossier TMP
File f1 = new File(TMP_UPLOAD_FOLDER);
boolean bool = f1.mkdir();
byte[] bytes = file.getBytes();
Path path = Paths.get(TMP_UPLOAD_FOLDER + file.getOriginalFilename());
System.out.println(path.toString());
Files.write(path, bytes);
System.out.println("File successfully uploaded to local storage : " + file.getOriginalFilename());
ftp.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out)));
int reply;
ftp.connect(SERVER_DOMAIN);
reply = ftp.getReplyCode();
if (!FTPReply.isPositiveCompletion(reply)) {
ftp.disconnect();
System.out.println("Exception in connecting to FTP Server");
}
ftp.login(SERVER_USERNAME, SERVER_PASSWORD);
ftp.setFileType(FTP.BINARY_FILE_TYPE);
ftp.setFileTransferMode(FTP.BINARY_FILE_TYPE);
ftp.enterLocalPassiveMode();
try {
InputStream input = new FileInputStream(new File(TMP_UPLOAD_FOLDER + file.getOriginalFilename()));
System.out.println(input);
ftp.storeFile("/home/myproject/public_html/tmp/" + file.getOriginalFilename().toString()+"", input);
ftp.logout();
ftp.disconnect();
System.out.println("File Uploaded !");
input.close();
Files.delete(path);
System.out.println("File deleted");
} catch (Exception e) {
System.out.println("Error uploading file to remote server");
}
}
return "";
}
I have a problem while uploading an image in an FTP server (using Cpanel) in production env with spring and angular technology.
The file is uploaded to the specified folder tmp but the image uploaded is corrupted and cannot be shown with this error 404 (Not Found).
When i upload the same image manually from cPanel, it works perfectly.
Any propositions please :)
Here is the source code :
public class FTPService {
static FTPClient ftp = new FTPClient();
static String TMP_UPLOAD_FOLDER = "/home/myproject/public_html/tmp/";
static String SERVER_DOMAIN = " XX.XXX.XX.XX";
static String SERVER_USERNAME = "username1";
static String SERVER_PASSWORD = "myPassword";
public static String uFileUpload(MultipartFile file, String TypePhoto, Long clientId) throws IOException {
if (file.isEmpty()) {
System.out.println("Empty File");
return "Empty File";
} else {
// dossier TMP
File f1 = new File(TMP_UPLOAD_FOLDER);
boolean bool = f1.mkdir();
byte[] bytes = file.getBytes();
Path path = Paths.get(TMP_UPLOAD_FOLDER + file.getOriginalFilename());
System.out.println(path.toString());
Files.write(path, bytes);
System.out.println("File successfully uploaded to local storage : " + file.getOriginalFilename());
ftp.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out)));
int reply;
ftp.connect(SERVER_DOMAIN);
reply = ftp.getReplyCode();
if (!FTPReply.isPositiveCompletion(reply)) {
ftp.disconnect();
System.out.println("Exception in connecting to FTP Server");
}
ftp.login(SERVER_USERNAME, SERVER_PASSWORD);
ftp.setFileType(FTP.BINARY_FILE_TYPE);
ftp.setFileTransferMode(FTP.BINARY_FILE_TYPE);
ftp.enterLocalPassiveMode();
try {
InputStream input = new FileInputStream(new File(TMP_UPLOAD_FOLDER + file.getOriginalFilename()));
System.out.println(input);
ftp.storeFile("/home/myproject/public_html/tmp/" + file.getOriginalFilename().toString()+"", input);
ftp.logout();
ftp.disconnect();
System.out.println("File Uploaded !");
input.close();
Files.delete(path);
System.out.println("File deleted");
} catch (Exception e) {
System.out.println("Error uploading file to remote server");
}
}
return "";
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论