使用 Javascript 上传 Parse.File

Uploading a Parse.File with Javascript

如何从表单中获取文件并将其保存到 Parse? 我尝试了几十种变体:

<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>

并在 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());

我尝试按照他们在 Parse 的 JS 指南 (https://parse.com/docs/js/guide) 中所说的方式进行操作,但这也不起作用。它似乎没有从表单中获取任何内容。我错过了什么?

试试这个

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