Uncaught TypeError: Can not read property 'getFile' of undefined [duplicated]

1

Hello, how am I trying an html course? I have reached a point where I can not move forward for the following reason. I am using apifile to create and read files.

then when you click on accept I get the following error

Uncaught TypeError: Can not read property 'getFile' of undefined

my JavaScript code is as follows

var ruta;
var espacio;
var zonadatos;
var lector;
function comenzar(){
  zonadatos = document.getElementById("zonadatos");
  var boton = document.getElementById("boton");
  boton.addEventListener("click",crear,false);

  //pedir permiso a nuestro navegador para acceder a nuestro disco duro
  navigator.webkitPersistentStorage.requestQuota(5*1024*1024,acceso); 
  //5megas
}

function acceso(){ //lanza un objeto filesystem
  //creacion de sistema de archivos
  window.webkitRequestFileSystem(PERSISTENT, 5*1024*1024, crearsis, 
  errores);
}

function crearsis(sistema){
  espacio = sistema.root; //sera la raiz de nuestro sistema de archivos
  ruta="";
  mostrar();
} 

function crear(){
      var nombre_archivo=document.getElementById("entrada").value;

      if(nombre_archivo!=""){
      nombre_archivo=ruta+nombre_archivo;
      espacio.getFile(nombre_archivo, {create:true, exclusive:false}, 
      mostrar,errores);
   }
 }

function mostrar(){
  document.getElementById("entrada");
  zonadatos.innerHTML="";
  espacio.getDirectory(ruta, null,leerdir,errores);
}

function leerdir(dir){
  lector=dir.createReader();
  leer();
}

 function leer(){
      lector.readEntries(function(archivos){
        if(archivos.length){
        listar(archivos);
      }
   },errores);  
 }

function listar(archivos){
   for(var i=0; i < archivos.length; i++){
       if(archivos[i].isFile){
        zonadatos.innerHTML+=archivos[i].name+"<br>";
       }else if(archivos[i].isDirectory){
          zonadatos.innerHTML+="<span 
       class='directorio'>"+archivos[i].name+"</span><br>";
       }
    }
 }
 function volver(){
        espacio.getDirectory(ruta,null,function(diractual){
        diractual.getParent(function(dirpadre){
        ruta=dirpadre.fullPath;
        mostrar();
      }, errores);
   },errores);
 }

 function errores(e){
     alert("ha habido un error" + e.code);
  }

   window.addEventListener("load", comenzar,false);

I've been thinking about it for a long time. I'd like to know if you can help me with guidance. thanks

    
asked by Vladimir Joel 03.09.2018 в 05:52
source

1 answer

0

The create function does not know what space it is. As Vladimir told you, to create, space is a null. Well, it's not in the scope of the function.

    
answered by 04.09.2018 в 09:50