1078-添加录像上传
This commit is contained in:
@@ -21,7 +21,7 @@ public class FtpServerConfig {
|
||||
private UserManager userManager;
|
||||
|
||||
@Autowired
|
||||
private FtpPlet ftpPlet;
|
||||
private ftplet ftpPlet;
|
||||
|
||||
/**
|
||||
* ftp server init
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
package com.genersoft.iot.vmp.conf.ftpServer;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 配置文件 user-settings 映射的配置信息
|
||||
*/
|
||||
@Component
|
||||
@ConfigurationProperties(prefix = "ftp", ignoreInvalidFields = true)
|
||||
@Order(0)
|
||||
public class FtpSetting {
|
||||
|
||||
private Boolean enable = Boolean.FALSE;
|
||||
|
||||
private String ip;
|
||||
private int port = 21;
|
||||
private String username = "admin";
|
||||
private String password = "admin";
|
||||
|
||||
public Boolean getEnable() {
|
||||
return enable;
|
||||
}
|
||||
|
||||
public void setEnable(Boolean enable) {
|
||||
this.enable = enable;
|
||||
}
|
||||
|
||||
public String getIp() {
|
||||
return ip;
|
||||
}
|
||||
|
||||
public void setIp(String ip) {
|
||||
this.ip = ip;
|
||||
}
|
||||
|
||||
public int getPort() {
|
||||
return port;
|
||||
}
|
||||
|
||||
public void setPort(int port) {
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,8 @@ package com.genersoft.iot.vmp.conf.ftpServer;
|
||||
|
||||
import com.genersoft.iot.vmp.jt1078.event.FtpUploadEvent;
|
||||
import org.apache.ftpserver.ftplet.*;
|
||||
import org.apache.ftpserver.impl.DefaultFtpSession;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
@@ -12,9 +13,9 @@ import java.io.IOException;
|
||||
|
||||
|
||||
@Component
|
||||
public class FtpPlet extends DefaultFtplet {
|
||||
public class ftplet extends DefaultFtplet {
|
||||
|
||||
private FtpletContext ftpletContext;
|
||||
private final Logger logger = LoggerFactory.getLogger(ftplet.class);
|
||||
|
||||
@Value("${ftp.username}")
|
||||
private String username;
|
||||
@@ -28,22 +29,26 @@ public class FtpPlet extends DefaultFtplet {
|
||||
return FtpletResult.DISCONNECT;
|
||||
}
|
||||
super.beforeCommand(session, request);
|
||||
// if (request.getCommand().equalsIgnoreCase("STOR") ) {
|
||||
// FtpUploadEvent ftpUploadEvent = new FtpUploadEvent(this);
|
||||
// ftpUploadEvent.setFileName(request.getArgument());
|
||||
// applicationEventPublisher.publishEvent(ftpUploadEvent);
|
||||
// }
|
||||
return FtpletResult.DEFAULT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FtpletResult onUploadStart(FtpSession session, FtpRequest request) throws FtpException, IOException {
|
||||
DefaultFtpSession ftpSession = (DefaultFtpSession) session;
|
||||
return super.onUploadStart(session, request);
|
||||
public FtpletResult onUploadEnd(FtpSession session, FtpRequest request) throws FtpException, IOException {
|
||||
FtpUploadEvent event = new FtpUploadEvent(this);
|
||||
event.setFileName(session.getFileSystemView().getFile(request.getArgument()).getAbsolutePath());
|
||||
applicationEventPublisher.publishEvent(event);
|
||||
|
||||
logger.info("[文件已上传]: {}", session.getFileSystemView().getFile(request.getArgument()).getAbsolutePath());
|
||||
return super.onUploadEnd(session, request);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FtpletResult onUploadEnd(FtpSession session, FtpRequest request) throws FtpException, IOException {
|
||||
public FtpletResult onAppendEnd(FtpSession session, FtpRequest request) throws FtpException, IOException {
|
||||
FtpUploadEvent event = new FtpUploadEvent(this);
|
||||
event.setFileName(session.getFileSystemView().getFile(request.getArgument()).getAbsolutePath());
|
||||
applicationEventPublisher.publishEvent(event);
|
||||
|
||||
logger.info("[文件已上传]: {}", session.getFileSystemView().getFile(request.getArgument()).getAbsolutePath());
|
||||
return super.onUploadEnd(session, request);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user