2013-07-08 3 views
4

Я использую js api для parse.com из приложения Angular js. Я пытаюсь сохранить/обновить изображение профиля пользователя. У меня есть следующий код:TypeError: Невозможно вызвать метод «then» неопределенного в Object.Parse.File.save

Некоторые html. , ,

<input type="file" capture="camera" accept="image/*" id="profilePhotoFileUpload"> 

Thansk к google i/o и raymond и parse js guide

код в мой контроллер:

$scope.updateUserProfile = function (user) { 

     var fileUploadControl = $("#profilePhotoFileUpload")[0]; 
     if (fileUploadControl.files.length > 0) { 
      var file = fileUploadControl.files[0]; 
      var name = "photo.jpg"; 

      var parseFile = new Parse.File(name, file); 

      parseFile.save(); 


} 

Я получаю эту ошибку:

TypeError: Невозможно вызвать метод 'затем' неопределенных на Object.Parse.File.save (parse-1.2.8.js: 4084: 43)

enter image description here

при вызове parseFile.save()

в основном _source не определено. , , Зачем?!

Спасибо!

ответ

1

Я, наконец, работаю, потому что моей конечной целью было использовать его с телефонной связью, with the info in this post.. Большое спасибо Раймонду Камдену!

функция gotPic (данные) {

window.resolveLocalFileSystemURI(data, function(entry) { 

    var reader = new FileReader(); 

    reader.onloadend = function(evt) { 
     var byteArray = new Uint8Array(evt.target.result); 
     var output = new Array(byteArray.length); 
     var i = 0; 
     var n = output.length; 
     while(i < n) { 
      output[i] = byteArray[i]; 
      i++; 
     }     
     var parseFile = new Parse.File("mypic.jpg", output); 

     parseFile.save().then(function(ob) { 
       navigator.notification.alert("Got it!", null); 
       console.log(JSON.stringify(ob)); 
      }, function(error) { 
       console.log("Error"); 
       console.log(error); 
      }); 

    } 

    reader.onerror = function(evt) { 
      console.log('read error'); 
      console.log(JSON.stringify(evt)); 
     } 

    entry.file(function(s) { 
     reader.readAsArrayBuffer(s); 
    }, function(e) { 
     console.log('ee'); 
    }); 

}); 

}

1

Если кто-то работает PhoneGap и Синтаксический анализ, вот еще один полезный пример из Raymond Camden, что делает снимок:

http://www.raymondcamden.com/2013/07/23/better-example-of-phonegap-parse-and-uploading-files

var imagedata = "";  

$("#takePicBtn").on("click", function(e) { 
    e.preventDefault(); 
    navigator.camera.getPicture(gotPic, failHandler, 
     {quality:50, destinationType:navigator.camera.DestinationType.DATA_URL, 
     sourceType:navigator.camera.PictureSourceType.PHOTOLIBRARY}); 
}); 

function gotPic(data) { 
    console.log('got here'); 
    imagedata = data; 
    $("#takePicBtn").text("Picture Taken!").button("refresh"); 
} 

и он сохраняется как:

var parseFile = new Parse.File("mypic.jpg", {base64:imagedata}); 
     console.log(parseFile); 
      parseFile.save().then(function() { 
       var note = new NoteOb(); 
       note.set("text",noteText); 
       note.set("picture",parseFile); 
       note.save(null, { 
        success:function(ob) { 
         $.mobile.changePage("#home"); 
        }, error:function(e) { 
         console.log("Oh crap", e); 
        } 
       }); 
       cleanUp(); 
      }, function(error) { 
       console.log("Error"); 
       console.log(error); 
      }); 

Особенно обратите внимание на {base64:imagedata}, так как это является ключом для создания файла синтаксического анализа с использованием строковых данных, как это.

Смежные вопросы