TypeError: Unable to call the 'then' method from undefined in Object.Parse.File.save

I am using js api for parse.com from an Angular js application. I am trying to save / update a user profile picture. I have the following code:

Some html.,.

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

Thansk to google i / o and raymond and parse js guide

in my controller:

 $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(); } 

I keep getting this error:

TypeError: Unable to call the 'then' method from undefined in Object.Parse.File.save (parse-1.2.8.js: 4084: 43)

enter image description here

when calling parseFile.save ()

mostly source _ undefined., why ?!

Thanks!

+4
source share
2 answers

I am finally working on this, since my ultimate goal was to use it with telephone communications, with the information in this message. . Many thanks to Raymond Camden!

getPic function (data) {

 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
source

If anyone else works with Phonegap and Parse, here is another useful example from Raymond Camden that takes a picture:

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"); } 

and it is saved as:

 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); }); 

Pay particular attention to {base64:imagedata} , as this is the key to creating a parsing file using string data like this.

+1
source

Source: https://habr.com/ru/post/1490198/


All Articles