0

このようにzipファイルをローカルに抽出するためにアドオンを機能させたい(here)。しかし、Firefox SDK を使用する際に問題が発生します。fileinputのパスを取得する際に問題が発生し、 dataTypeが ArrayBuffer ではないため、サポートされていない形式のエラーが発生したため、zip を読み取ることができません。

HTML

<input type="file" name="file" id="import" class="hide" />

myscript.js

var fileInput = document.getElementById('import');
fileInput.addEventListener('change', function(e) {
    var zipFileToLoad = fileInput.files[0];
    var tampJson = [];
    JSZip.loadAsync(zipFileToLoad)
            .then(function(zip) {
                console.dir(zip);
                zip.forEach(function (relativePath, zipEntry) {
                    if(zipEntry.dosPermissions == null){
                        alert('Permissions trouble !')
                    }
                    if(typeof(zipEntry['_data']['compressedContent']) != 'undefined'){
                        //var text = String.fromCharCode.apply(null, new Uint8Array(zipEntry['_data']['compressedContent']));
                        var text = new TextDecoder("utf-8").decode(zipEntry['_data']['compressedContent']);
                        var dec = text.toString();

                        var json = JSON.parse(dec);
                        if(json != null){
                            var keys = ['name', 'description', 'data', 'created_at', 'updated_at'];
                            keys.forEach(function(key){
                                if (key in json){
                                    if(key == keys[keys.length - 1]){
                                        tampJson.push(json);
                                    }
                                }else{
                                    dialog({
                                        title: "Warning",
                                        description: "<b>Wrong format, </b> are you sure to continue?",
                                        yesButton: "yes",
                                        cancelButton: "No",
                                        yesCallback: function() {
                                            $(this).closest('.overlay').removeClass("active");
                                        },
                                        cancelCallback: function() {
                                            $(this).closest('.overlay').removeClass("active");
                                            return false;
                                        }
                                    });
                                }
                            });
                        }else{
                            alert('format parse gagal');
                        }
                    }
                });
                if(tampJson.length > 0){
                    saveByImport(tampJson, 0);
                }else{
                    alert('Oops file empty');
                }
            }, function (e) {
                alert('Oops import fail '+ e);
            });

コンソールでエラーできません。fileinput から ArrayBuffer を取得できません。このスクリプトは Chrome 拡張機能では機能しますが、Firefox SDK では機能しません。この問題を解決するために私を助けてください。

4

1 に答える 1