2016-10-24 42 views
1

JSZipで入力からジップの内容を取得したいと思います。 私は私のファイルのタイトルを読み取ることができますが、どのように私はjQueryを使ってみましコンテンツJSZip:ファイル入力からzipファイルの内容を取得

入手できます:

$('.upload-input').on('change', function($event) { 
var $file = $event.target.files[0]; 
JSZip.loadAsync($file).then(function($content) { 
    alert($content.files["css/style.css"].async('text')); 
}) 
}); 

リターン:[オブジェクトの約束]

私は平野を取得するために何ができるのをテキスト

JSFiddle:https://jsfiddle.net/jyuy7q6j/

THX!

答えて

4

asyncのように、loadAsyncPromiseを返します。ここでそれらをチェーンすることができます:

$('.upload-input').on('change', function($event) { 
var $file = $event.target.files[0]; 
JSZip.loadAsync($file).then(function($content) { 
    // if you return a promise in a "then", you will chain the two promises 
    return $content.files["css/style.css"].async('text'); 
}).then(function (txt) { 
    alert(txt); 
}); 
}); 
+0

ありがとう – howtoweb

関連する問題