2

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?

1 Answer 1

2

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);
     }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.