Is it possible to append Media's file browser to a certain node type? I have a certain node type with a canvas on it, allowing users to draw on the node. Basic functionality such as lines are working, but I'd like to allow people to upload images to it as well. Since the rest of the site is using the Media module (V2 dev), allowing users to browse the library and their personal uploads... I was hoping to be able to use it here as well.

The same question was posted as a support request in Media issue queue as well but so far there is no reponse: https://www.drupal.org/node/2423415

What I am looking for is a way to embed the media browser on the node and catch the path of the returned file so the JavaScript and the canvas can read it. 

So far I've managed to add the media widget to the node with:

function mymodule_node_view($node, $view_mode, $langcode) {
  if($node-&gt;type == 'mytype') {
    $form = drupal_get_form('mymodule_media_form');

    // append a new field to the content
    $node-&gt;content['imageupload'] = array(
      '#markup' =&gt; drupal_render($form), // and render the form there
      '#weight' =&gt; 10,
    );
  }
}

function mymodule_media_form($form, &amp;$form_state) {
  $form['file'] = array(
    '#type' =&gt; 'media-widget',
    '#title' =&gt; t('Image'),
    '#description' =&gt; t('Upload a file'),
  );
  return $form;
}


It shows the Media file upload button, but the dialog does not popup (due to missing JavaScripts I suppose). Is there a better way to load this field with all required JS etc? I do suppose I need to at least use hook_form() assuming I can't display a form field outside form context.
It appeared I had been using the wrong form element. My custom form was created as below:

function mymodule_file_upload_form($form, &amp;$form_state) {
  $form['file'] = array(
    '#type' =&gt; 'media',
    '#title' =&gt; t('Choose an image'),
    '#description' =&gt; t('Choose an image'),
    '#tree' =&gt; TRUE,
    '#input' =&gt; TRUE,
    '#media_options' =&gt; array(
      'global' =&gt; array(
        'file_extensions' =&gt; 'gif jpg jpeg png',
        'file_directory' =&gt; 'conferences',
        'types' =&gt; array(
          'image',
        ),
        'schemes' =&gt; array(
          'private' =&gt; 'private',
        ),
        'enabledPlugins' =&gt; array(
          'upload',
          'media_default--media_browser_my_files',
        ),
      ),
    ),
  );

  return $form;
}


And then with some javascript I manged to get the fid of the file

$("form").on("change", "input.upload", function() {
  var val = $(this).val();
  $.ajax({
    url: Drupal.settings.basePath + 'draw/file/' + val,
    success: function(data) {
      src = data
    }
  });
});


That path was registered in hook_menu() to return the path of the private file as per:

function mymodule_menu() {
  $items['draw/file/%file'] = array(
    'page callback' =&gt; 'mymodule_page_file',
    'page arguments' =&gt; array(2),
    'access arguments' =&gt; 'view own private files',
  );
  return $items;
}


function mymodule_page_file($file) {
  global $user;
  if($user-&gt;uid == $file-&gt;uid) {
    echo file_create_url($file-&gt;uri); // Use echo to prevent theme to appear.
  }
}