2017-04-17 12 views
0

handleFiles(appCSV)을 건너 뛰고 대신 undefined을 반환하는 것으로 나타났습니다.FileReader API가 2.5MB이고 Chrome을 사용하더라도 내 메서드를 건너 뜁니다.

appDictionary = handleFiles(appCSV); 
dbDictionary = handleFiles(dbCSV); 

appCSV 파일 크기는 2584729 bytes 또는 약 2.5 MB입니다. 그로 인한 문제입니까?

이미 Chrome 57을 사용하고 있기 때문에 이상합니다.

해결책이나 해결 방법을 조사하고 제공하는 데 도움을주십시오. 감사! handleFiles 기능의

바디 : 나는 내 자신의 문제를 해결 한

function handleFiles(files) { 
    // Check for the various File API support. 
    if (window.FileReader) { 
     // FileReader are supported. 
     getAsText(files[0]); 
    } else { 
     alert('FileReader are not supported in this browser.'); 
    } 
} 

function getAsText(fileToRead) { 

    let reader = new FileReader(); 
    // Handle errors load 
    reader.onload = loadHandler; 
    reader.onerror = errorHandler; 
    // Read file into memory as UTF-8  
    reader.readAsText(fileToRead); 

} 

function loadHandler(event) { 
    let csv = event.target.result; 
    processDataToDictionary(csv); 
} 

function errorHandler(evt) { 
    if (evt.target.error.name == "NotReadableError") { 

     alert("Cannot read file!"); 

    } 
} 
+1

이'handleFiles' 함수의 본문을 보여줄 수 있습니까? 그러나 필자가 작성한대로 필자는 FileReader의 onload 이벤트를 기다리지 않고 이미 readAs ... 메소드가 모두 비동기식이라는 사실을 알고있다. – Kaiido

+2

[비동기 호출의 응답을 어떻게 반환합니까?] (http://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call)의 가능한 복제본 – Kaiido

+0

@Kaiido 안녕하세요, handleFiles 함수의 본문을 게시했습니다. IT 부서는'dbDictionary = handleFiles (dbCSV);를 건너 뛰지는 않습니다 만'appDictionary' 만 건너 뜁니다. 친절하게 조사하도록 도와주세요. – JPaulPunzalan

답변

0

. onLoad 이벤트가 FileReader API 인 것은 asynchronous입니다.

그래서 handleFiles() 함수를 onchange() propertyinput type = 'file'에 넣기로 결정했습니다.