Skip to content

Instantly share code, notes, and snippets.

@robcmills
Last active August 29, 2015 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robcmills/cd93175f9d3d5a22eea5 to your computer and use it in GitHub Desktop.
Save robcmills/cd93175f9d3d5a22eea5 to your computer and use it in GitHub Desktop.
how the Go Game app gets media

user clicks on HTML file input element

<form enctype="multipart/form-data" class='media-upload-form'>
<div class='upload_container'>
  <input type="file" name="file" 
    id="fileUpload{{unbound view.elementId}}"
    accept="{{unbound view.accept}}">
</div>

where view.accept = 'video/*' or 'image/*'

we capture click/touch event and if in native app we make a call into forge's native hooks:

  _getMedia: function(func, options, success, error) {
    forge.file[func](options, function(file) {
      if(forge.file.info) {
        forge.file.info(file, function(info) {
          file.timestamp = moment(info.date).unix();
          file.size = info.size;
          success(file);
        }, error);
      } else {
        file.timestamp = Math.floor(Breadcrumb.now() / 1000);
        file.size = 0;
        success(file);
      }
    }, error);
  },

where func = 'getImage' or 'getMedia'

essentially we are using forge.file.getVideo and forge.file.getImage (these are links to the documentation)

which return us a javascript file object that we then upload with forge.request.ajax

so what we need is a custom forge module that extends the functionality of forge.file.getVideo with compression and a forced review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment