title: How to send file from Mayan EDMS to external api?
body: <p>I'm still learning Django and there is still a lot of unknown to me.</p>
  
  <p>The problem is that I can't pull the .pdf (or any other format) to be sent by ajax post method to external API. So on the reciving side I only get the string location of the file not the actual file.</p>
  
  <p>I have put the following javascript code in the <em>generic_list_items_subtemplate.html</em></p>
  
  <pre><code>{% load i18n %}
  {% load static %}
  
  {% load common_tags %}
  {% load navigation_tags %}
  
  &lt;div class="row"&gt;
      &lt;div class="col-xs-12"&gt;
          &lt;h4&gt;
              {% if page_obj %}
                  {% if page_obj.paginator.num_pages != 1 %}
                      {% blocktrans with page_obj.start_index as start and page_obj.end_index as end and page_obj.paginator.object_list|length as total and page_obj.number as page_number and page_obj.paginator.num_pages as total_pages %}Total ({{ start }} - {{ end }} out of {{ total }}) (Page {{ page_number }} of {{ total_pages }}){% endblocktrans %}
                  {% else %}
                      {% blocktrans with page_obj.paginator.object_list|length as total %}Total: {{ total }}{% endblocktrans %}
                  {% endif %}
              {% else %}
                  {% blocktrans with object_list|length as total %}Total: {{ total }}{% endblocktrans %}
              {% endif %}
          &lt;/h4&gt;
          &lt;hr&gt;
          &lt;div class="well center-block"&gt;
              &lt;div class="clearfix"&gt;
                  &lt;div class="pull-right"&gt;
                      &lt;form action="{% url 'common:multi_object_action_view' %}" class="form-multi-object-action" method="get"&gt;
                          {% if object_list %}
                              {% if not hide_multi_item_actions %}
                                  {% get_multi_item_links_form object_list %}
                              {% endif %}
                              {% if multi_item_actions %}
                                  &lt;fieldset style="margin-top: -10px;"&gt;
                                      &lt;input class="check-all" type="checkbox"/&gt;&amp;nbsp;
                                      {{ multi_item_form }}
                                  &lt;/fieldset&gt;
                              {% endif %}
                          {% endif %}
                      &lt;/form&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
  
              {% if object_list %}
                  &lt;hr style="border-bottom: 1px solid lightgrey;"&gt;
  
              {% endif %}
  
  
              &lt;div class="row row-items"&gt;
                  {% for object in object_list %}
                      &lt;div class="{{ column_class|default:'col-xs-12 col-sm-4 col-md-3 col-lg-2' }}"&gt;
                          &lt;div class="panel panel-primary panel-item"&gt;
                              &lt;div class="panel-heading"&gt;
                                  &lt;div class="form-group" id="myform"&gt;
  
                                      &lt;div class="checkbox"&gt;
                                          &lt;label for="id_indexes_0"&gt;
                                              {% if multi_item_actions %}
                                                  {% if multi_select_item_properties %}
                                                      &lt;input class="form-multi-object-action-checkbox check-all-slave checkbox" type="checkbox" name="properties_{{ object|get_encoded_parameter:multi_select_item_properties }}" /&gt;
                                                  {% else %}
                                                      &lt;input class="form-multi-object-action-checkbox check-all-slave checkbox" type="checkbox" name="{{ object.get_absolute_url }}" /&gt;
                                                  {% endif %}
                                              {% endif %}
  
                                              &lt;span style="color: white; word-break: break-all; overflow-wrap: break-word;"&gt;
                                                  {% if not hide_object %}
                                                      {% if main_object %}
                                                          {% with object|object_property:main_object as object %}
                                                              {% if not hide_link %}&lt;a name="test" href="{{ object.get_absolute_url }}"&gt;{{ object }}&lt;/a&gt;{% else %}{{ object }}{% endif %}
                                                          {% endwith %}
                                                      {% else %}
                                                          {% if not hide_link %}&lt;a href="{{ object.get_absolute_url }}"&gt;{{ object }}&lt;/a&gt;{% else %}{{ object }}{% endif %}
                                                      {% endif %}
                                                  {% endif %}
  
                                              &lt;/span&gt;
                                          &lt;/label&gt;
                                      &lt;/div&gt;
                                  &lt;/div&gt;
  
                              &lt;/div&gt;
                              &lt;div class="panel-body"&gt;
  
                                  {% if not hide_columns %}
                                      {% for column in object|get_source_columns %}
                                          &lt;div class="text-center" style=""&gt;{% source_column_resolve column=column %}{{ column_result }}&lt;/div&gt;
                                      {% endfor %}
                                  {% endif %}
  
                                  {% for column in extra_columns %}
                                      &lt;div class="text-center"&gt;&lt;span class="list-extra-column-label"&gt;{{ column.name }}&lt;/span&gt;: {{ object|object_property:column.attribute }}&lt;/div&gt;
                                  {% endfor %}
  
                                  {% if not hide_links %}
                                      &lt;p class="text-center"&gt;
                                          {% get_menu_links 'object menu' source=object as resolved_links %}
                                          {% for object_navigation_links in resolved_links %}
                                              {% with 'true' as as_dropdown %}
                                                  {% include 'navigation/generic_navigation.html' %}
                                              {% endwith %}
                                          {% endfor %}
                                      &lt;/p&gt;
                                  {% endif %}
  
                              &lt;/div&gt;
                          &lt;/div&gt;
                      &lt;/div&gt;
                  {% empty %}
                      &lt;div class="col-xs-12"&gt;
                          {% include 'appearance/no_results.html' %}
                      &lt;/div&gt;
  
                  {% endfor %}
  
              &lt;/div&gt;
  
              &lt;!--&lt;/form&gt;--&gt;
  
  
  
  
              {% include 'pagination/pagination.html' %}
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  
              &lt;!--{% if object_list %}--&gt;
              &lt;form method="post"&gt;
                  {% csrf_token %}
                  &lt;input type="hidden" name="csrf-token" value="nc98P987bcpncYhoadjoiydc9ajD1cn"&gt;
                      &lt;div class="row"&gt;
                          &lt;div class="col-md-3"&gt;&lt;/div&gt;
                          &lt;div class="col-md-3"&gt;
                              &lt;button id="sendBTN" class="btn btn-success" type="submit"&gt;Send checked documents to another database&lt;/button&gt;
                          &lt;/div&gt;
                          &lt;div class="col-md-3"&gt;&lt;/div&gt;
                      &lt;/div&gt;
              &lt;/form&gt;
  
              &lt;br&gt;
              &lt;br&gt;
              &lt;br&gt;
              &lt;!--{% endif %}--&gt;
  
  
  &lt;script type="text/javascript"&gt;
      'use strict';
  
      var $data = [];
  
      $(document).on("click", "input[type='checkbox']", (e) =&gt; {
          var name = $(e.target).attr("name");
          if($(e.target).prop("checked")){
              $data.push(name);
          }else{
              $data = jQuery.grep($data, function(value) {
                return value != name;
              });
          }
          console.log($data);
      });
  
  
               function csrfSafeMethod(method)
               {
                   return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method));
               }
  
               $.ajaxSetup({
                   beforeSend: function (xhr, settings) {
                       if(!csrfSafeMethod(settings.type) &amp;&amp; !this.crossDomain)
                       {
                           xhr.setRequestHeader("X-CSRFToken", csrftoken);
                       }
                   }
               });
  
  
  
      document.getElementById("sendBTN").onclick = function() {
  
           var form_data  = new FormData();
           // form_data.append('file', $('#myform').get(0));
  
           form_data.append('file', $data);
  
           console.log(form_data);
  
           $.ajax({
               type: "POST",
               // contentType: "application/x-www-form-urlencoded",
               contentType : false,
               processData: false,
               url: "http://192.168.10.22:5000/api/FileRecive/GetDocument",
               dataType: "json",
               data: form_data,
               success: function (data) {
                   data = $.parseJSON(data);
                   alert("success");
               },
               error: function (xhr) {
                   alert("error - " + xhr.statusText);
               }
           });
      };
  
  
      $(function() {
          $('.row-items &gt; [class*="col"] .panel-item .panel-heading').matchHeight();
          $('.row-items &gt; [class*="col"] .panel-item .panel-body').matchHeight();
          $('.row-items &gt; [class*="col"] .panel-item').matchHeight();
      });
      &lt;/script&gt;
  </code></pre>
  
  <p>On the reciving side I am getting </p>
  
  <pre><code>name = "file"
  value = "/documents/12/preview/"
  </code></pre>
  
  <p>But I want to get the file not this string. I have no idea how to target file to send it dirrectly.</p>
  
  <p><a href="https://i.stack.imgur.com/k9Sjm.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/k9Sjm.png" alt="enter image description here"></a></p>