Reputation: 1127
How do I get the file from the form to save it to Parse? I tried several dozen variations of this:
<form id="image_form" enctype="multipart/form-data" action="/upload/image" method="post">
<h3>Upload icon image: </h3>
<p><input id="image_file" name="image_file" type="file"></p>
<p><input id="event_submit" type="submit" value="Create" onclick="makeEventSnip();"></p>
</form>
and in the javascript:
function makeEventSnip() {
event.preventDefault();
var fileUploadControl = document.getElementById('image_file');
var file = fileUploadControl.files[0];
var name = "icon.png";
var iconImageFile = new Parse.File(name, file);
alert(iconImageFile.getUrl());
I tried to do it the way they say to in Parse's JS Guide (https://parse.com/docs/js/guide) but that doesn't work either. It doesn't appear to be grabbing anything from the form. What am I missing?
Upvotes: 2
Views: 2630
Reputation: 1021
try this
var fileUploadControl = document.getElementById('image_file');
var file = fileUploadControl.files[0];
var name = "icon.png";
var iconImageFile = new Parse.File(name, file);
iconImageFile.save().then(function() {//you need to call after save the file
alert(iconImageFile._url);
}
Upvotes: 2