繁体   English   中英

Vaadin EasyUpload加载项有时无法打开或找到指定的文件

[英]Vaadin EasyUpload add-on sometimes could not open or find file specified

我们当前正在使用EasyUpload附加组件,并且已经为此组件指定了条件:

a)只允许CSV文件,每个文件的上限为1MB。 b)一次只能提交一个文件。

我们刚刚对100Kb以下的小型CSV文件进行了上传测试。 通常,上传过程会成功完成。 有时,尽管文件已经在temp文件夹中,但仍显示错误“无法打开文件,系统找不到指定的文件”,并且我们发现在以下情况下会发生这种情况:

a)如果进行了较小的更改后又在成功上传文件后的几秒钟内再次上传了同一文件。

b)如果该Web应用程序有两个选项卡,则在不同用户登录下分别上传了各自的csv文件,并且在再次上传它们之前,他们在更改csv中的值方面也做同样的事情。

我们尝试强制通过文件上传(作为另一种测试方法),过了一会儿,尽管我们在提交时间规则中强加了一个文件,但有时文件有时仍卡在队列中。 它显示在消息“文件数超出限制”中。 我们还考虑了在文件提交后的3-5秒内放置一个sleep / wait命令。

MultiFileUpload multiFileUpload = new MultiFileUpload() {
            @Override
            protected void handleFile(File tmpFile, String fileName, String mimeType, long length) {
                String[] header = {"EOD_NUM","OUTLET_NAME","POSM_NAME","EOD_DATE","TOTAL_SALES","GROSS_SALES",
                "TRAN_COUNT","VOID_COUNT","SERVICE_CHARGE","DISCOUNT_AMT","VAT_TAX_AMT","SVC_TAX_AMT","ROUNDING_ADJ"};

                uploadLogger.debug("File: " + tmpFile.getAbsolutePath());
                uploadLogger.debug("FileName: " + fileName);
                uploadLogger.debug("MimeType: " + mimeType);
                uploadLogger.debug("File Length: " + length);
                DateTimeFormatter dtf = DateTimeFormatter.ofPattern("ddMMyyyyHHmmss");
                LocalDateTime now = LocalDateTime.now();
                File f2 = null;
                f2 = new File(busId+"_"+dtf.format(now)+".csv");
                tmpFile.renameTo(f2);
                try {
                    ///var/lib/tomcat8/ in linux
                    ///D:\\home\\site\\wwwroot\\ in Windows
                    uploadLogger.debug("f2 absolutepath: " + f2.getAbsolutePath());
                    uploadLogger.debug("f2 canonical path: " + f2.getCanonicalPath());
                    CloudBlockBlob blob = container.getBlockBlobReference(f2.getName());
                    if(f2.length() > 0){
                        blob.uploadFromFile(f2.getAbsolutePath());
                        Notification.show("File upload completed.",Notification.Type.TRAY_NOTIFICATION);
                    }
                    CSVReader reader = new CSVReader(new FileReader(f2.getAbsolutePath()), ',' , '"' , 0);
                    //read header name
                    //String[] myheader = reader.readNext();

                    //NOTE :: Store all row and column from csv info List of String Array
                    myEntries = reader.readAll(); 
                    if (myEntries != null && !myEntries.isEmpty()) {
                        boolean success = uploadDAO.insertUploaderEntry(myEntries,busId, userId,"");
                        uploadLogger.debug("SUCCESSS??? " + success);
                        if(success){
                            Notification successNotify = new Notification("Record has been created successfully.","Upload Successful!");
                            successNotify.setDelayMsec(3000);
                            successNotify.setStyleName(ValoTheme.NOTIFICATION_SUCCESS);
                            successNotify.setPosition(Position.MIDDLE_CENTER);
                            successNotify.show(Page.getCurrent());
                        }else {
                            Notification.show("Error in submitting uploaded record.","Upload failed!"
                                    , Notification.Type.ERROR_MESSAGE).setDelayMsec(3000);
                        }
                        Thread.sleep(3000); //added to see if the delay solves the problem or not.
                    }
                } catch (URISyntaxException | StorageException | IOException ex) {
                    new Notification("Could not open file",ex.getMessage(),Notification.Type.ERROR_MESSAGE).show(Page.getCurrent());
                    uploadLogger.debug(ex);
                } catch (InterruptedException ix) {
                    uploadLogger.debug("Interrupted Exception found: " + ix.getMessage());
                } 
            }

            @Override
            protected boolean supportsFileDrops() {
                return false;
            }   
        };
        multiFileUpload.setMaxFileCount(1);
        multiFileUpload.setUploadButtonCaption("Upload CSV file here");
        multiFileUpload.setMaxFileSize(fileSizeLimit); // 2MB
        multiFileUpload.setAcceptFilter(".csv");

我们不确定此问题是否是组件的已知限制。

我们在此过程中发现的一些问题是:

a)是否有更好的方法或控制文件上传并避免打开文件/找不到文件错误?

b)setAcceptedFilter方法中的值是mime / type值还是其他值。 我们注意到图像是“ images / *”,但是对于csv,我们不得不输入为“ .csv”

回答第二个问题。 直接将acceptFilter传递到上传输入的“ accept”属性,因此.csv和text / csv都应该可以正常工作。 有关更多说明,请参见https://www.w3schools.com/tags/att_input_accept.asp

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM