2015-05-18 9 views
0

Я пытаюсь добавить данные в базу данных apigee из текстовых файлов. У меня есть несколько текстовых файлов, содержащих данные книг.Добавление текстового файла данных в базу данных apigee

Я могу добавить один книгу данные по этому коду:

function saveData(){ 
    //Initialize our client 
    var client = new Usergrid.Client({ 
     orgName:"orgname", 
     appName:"sandbox" 
    }); 

    //In our options object we set the type of the entitiy 
    //and we also set any data that goes along with it 
    //in this case it's the books title. 
    var options = { 
     type:"book", 
     title:"someTitle", 
     author:"someAuthor", 
     newElement:"Value" 
    }; 

    //Let's create our entity, and display the results 
    //of the creation in the html element with the id of response 
    client.createEntity(options, function(error, book){ 
     if(error) { 
      //error saving book 
      $("#response").append("There was an error!"); 
      alert("Error");   
     } else { 
      var uuid = book.get("uuid"); 
      var author = book.get("author"); 
      var title = book.get("title"); 
      $("#response").append("Book saved! Its uuid on our server is: "+uuid+"<br/>"); 
      $("#response").append("The book you saved was: "+title + "<br/>"); 
      $("#response").append("It's author is: "+author); 
      alert("Its working");    
     } 
    }); 
} 
saveData() 

Как получить доступ к .txt файлы и получить данные других книг из JavaScript? Я понимаю, что javascript позволяет добавлять файлы через пользовательский ввод с помощью FileReader(). Есть ли другой способ сделать это?

+0

К сожалению, Ваш вопрос не ясен. Вы пытаетесь прочитать TXT-файл из Node.js? Если это так, ваш вопрос не относится к Apigee. –

ответ

0

код вы предоставили не будет создавать какие-либо файлы с расширением .txt, но читать сохраненную книгу объект назад, вы могли бы сделать что-то вроде этого:

 books.fetch(
       function(err, data) { // Success 
        if (err) { 
         alert("read failed"); 
        } else { 
         while(books.hasNextEntity()) { 
          var book = books.getNextEntity(); 
          alert(book.get("title")); // Output the title of the book 
         } 
        } 
       });