我正在尝试使用Vaadin上传上传.xlsx文件,当我再次上传同一个文件时,没有任何事情发生,它也不会触发任何事件。我第一次可以上传文件,它工作得很好,但在那之后,当我尝试再次上传同一个文件时,没有任何反应。我无法弄清楚这个问题。
uploader = new Upload(null, this);
uploader.setImmediate(true);
uploader.setButtonCaption("Upload Template");
uploader.addStartedListener(this);
uploader.addFinishedListener(this);
@Override
public OutputStream receiveUpload(String filename, String mimeType) {
uploadedFilename = filename;
FileOutputStream fos = null; // Stream to write to
try {
String filepath = attachmentsTmpFolderLoc + File.separator + "Uploads";
File folder = new File(filepath);
if (!folder.exists()) {
folder.mkdirs();
}
uploadFile = new File(filepath + File.separatorChar + filename);
fos = new FileOutputStream(uploadFile);
} catch (Exception e) {
e.printStackTrace();
return new NullOutputStream();
}
return fos;
}
@Override
public void uploadStarted(StartedEvent event) {
uploader.setVisible(false);
}
@Override
public void uploadFinished(FinishedEvent event) {
uploader.setVisible(true);
getFinishedFile();
}
private void getFinishedFile() {
String loginUserId = activeUserObject.getLoginId();
String fileName = loginUserId + "_" + this.jobPkey + ".xlsx";
if (!validatFileName(loginUserId, this.jobPkey)) {
new IMCNotification().showError("Adressing - Wrong Template Name", "Please Upload file with Name : '" + fileName + "'.<BR> The uploaded file name should be the same as the downloaded file name.<BR> Please correct the file name and try again.");
uploader.interruptUpload();
} else {
prepareCustomValidations();
}
}