Saving file to drupal site using drupalgap I am trying to save an image from Android emulator to a Drupal site using DrupalGap, but I am unable to do this.  This is my ajax call which I wrote to save the data to drupal site.

My click function

   $('#page_node_create_submit').on('click',function(){

try {
      var title = $('#page_node_title').val();
      if (!title) { alert('Please enter a title.'); return false; }

      var body = $('#page_node_body').val();
      if (!body) { alert('Please enter a body.'); return false; }

      var filef = $('#page_node_filef').val();
      if (!filef) { alert('Please select file.'); return false; }

     //var datastring = 'node[type]=drupalgap&amp;node[title]=' + encodeURIComponent(title) + '&amp;node[language]=und&amp;node[body][und][0][value]=' + encodeURIComponent(body) + '&amp;node[files][field_filef_und_0]=' + '&amp;fid=47' + '&amp;uid=1';
     //alert(datastring);
     //return false;

      $.ajax({
          url:"http://192.168.1.146/drunew/?q=services/session/token",
          type:"get",
          dataType:"text",
          error:function (jqXHR, textStatus, errorThrown) {
            alert(errorThrown);
          },
          success: function (token) {
          // BEGIN: drupal services node create login (warning: don't use https if you don't have ssl setup)
          $.ajax({
              url: "http://192.168.1.146/drunew/?q=my_services/node.json",
              type: 'post',
              data: 'node[type]=drupalgap&amp;node[title]=' + encodeURIComponent(title) + '&amp;node[language]=und&amp;node[body][und][0][value]=' + encodeURIComponent(body) + '&amp;node[files][field_filef_und_0]=' + encodeURIComponent(filef),
              dataType: 'json',
              beforeSend: function (request) {
                        request.setRequestHeader("X-CSRF-Token", token);
                     },
              error: function(XMLHttpRequest, textStatus, errorThrown) {
                alert('page_node_create_submit - failed to login');
                console.log(JSON.stringify(XMLHttpRequest));
                console.log(JSON.stringify(textStatus));
                console.log(JSON.stringify(errorThrown));
              },
              success: function (data) {

               $.mobile.changePage("main.html", "slideup");
              }
          });
          // END: drupal services node create
          }
        });
    }catch (error) { alert("page_dashboard - " + error); }
return false;

});


But the above code is not working for file field, then after doing some R&amp;D I got to know that first we have to get the fid, then save it.

Below is the respone after creating the fid for the image.

{"fid":"47","uri":"http://192.168.1.146/drunew/my_services/file/47"}


Here my doubt is how can I integrate this response in my above ajax call to save the image in drupal site.

Any help, thanks..
Once you have the File ID, that means you've successfully saved the file to your Drupal site. Next up (typically), you'll want to attach that File ID to a new/existing Entity (e.g. node).

If you are creating a new node, use a POST, if updating an existing one, use a PUT.

New


  /my_endpoint/node.json


{
  type: 'article',
  language: 'und',
  title: 'Hello',
  file_images: {
    und: [ {fid: 12 }]
  }


}

Existing


  /my_endpoint/node/456.json


{
  type: 'article',
  language: 'und',
  title: 'Hello Again',
  file_images: {
    und: [ {fid: 12 }]
  }


}

FYI, the latest version of DrupalGap now supports image fields, so you shouldn't have to write any custom code.