我正在尝试使用 Vaadin Upload 上传 .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();
}
}