Ok, so I'm trying to figure out how to save images to Parse using Parse.Files, and then be able to retrieve the images later as well. Right now, whenever I load the page, a new Parse object is automatically created, but with the incorrect file.
What I want, is to be able to choose an image from file using an input field, upload it after clicking the upload button, and then be able to retrieve it later as well, again probably with some sort of button. I'm not sure where to really go from here, so any help is appreciated!!!
Code for my Buttons
<input type="file" class="imageFile" id="imageFile"/>
<input type="button" onclick="uploadImage()" class="uploadBtn" value="Upload Image" id="upload"/>
Javascript Code
<script type="text/javascript">
Parse.initialize("key", "key");
var GameScore = Parse.Object.extend("GameScore");
var gameScore = new GameScore();
function uploadImage() {
//var images = Parse.Object.extend("images");
var base64 = "V29ya2luZyBhdCBQYXJzZSBpcyBncmVhdCE=";
var file = new Parse.File("player1.png", { base64: base64 });
file.save({
success: function(file) {
alert('File saved, now saving product with file reference...');
// to fill the columns
gameScore.set("picture", file);
gameScore.save(null, {
success: function(gameScore) {
// Execute any logic that should take place after the object is saved.
gameScore.save();
alert('New object created with objectId: ' + gameScore.id);
},
error: function(error) {
// Execute any logic that should take place if the save fails.
// error is a Parse.Error with an error code and description.
alert('Failed to create new object, with error code: ' + error.description);
}
});
},
error: function(error) {
alert('Failed to save file: ' + error.description);
}
});
}
</script>