簡體   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