Upload Nodes with Image Fields I'm using jquery mobile and phonegap for a mobile app. I have uploaded an image file and received the fid but the subsequent request to create a node and attach the fid fails. The node is created although the image field is not filled in with the fid. Also the uploaded image in ../sites/default/files doesnot have dimensions(height and width).

Post the image:

var filedata = {
        "file":{
          "file":imageObj['base64s'][0],
          "filename":imageObj['names'][0],
          "filepath":"public://"+imageObj['names'][0],
          "mimeType":"image/"+imageObj['names'][0].split(".")[1],
          "filesize":  imageObj['sizes'][0]

        }
    }; 

$.ajax({
    url: localStorage.appurl+"/api/file.json",
    type: 'post',
    data: filedata,
    dataType: 'json',
    cache: false,
    headers: {
      'X-CSRF-Token': localStorage.usertoken
    },
    error: function(XMLHttpRequest, textStatus, errorThrown) {
      console.log('error '+errorThrown);
      d.reject(errorThrown);
    },
    success: function (data) {         
      d.resolve(data);

    }
  });


Create the node:

$.ajax({
url: localStorage.appurl+"/api/node.json",
type: 'post',
data: "node[title]=new node&amp;node[type]=ftritem&amp;node[field_ftritem_images[und][0][fid]=7895",
dataType: 'json',
heders: {
  'X-CSRF-Token': localStorage.usertoken
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
  console.log('error '+errorThrown);

},
success: function (data) {         
console.log("Node created");

}
});


Im getting this error:

Notice: Undefined offset: 0 in image_field_widget_form() (line 358 of /var/www/dt11/modules/image/image.field.inc).

Notice: Undefined offset: 0 in file_field_widget_form() (line 526 of /var/www/dt11/modules/file/file.field.inc).

Has anyone faced this before ? Any suggestions are highly appreaciated.
There is a problem in Drupal core. I made an issue for it here and a patch has been supplied, but it didn't work properly for me: https://www.drupal.org/node/1912458

I did get it to work by only doing part of what the patch does.

Find line 504 of modules/file/file.field.inc and change it from this:

if (($field['cardinality'] == FIELD_CARDINALITY_UNLIMITED || $delta &lt; $field['cardinality']) &amp;&amp; empty($form_state['programmed'])) {


To this:

if (($field['cardinality'] == FIELD_CARDINALITY_UNLIMITED || $delta &lt; $field['cardinality'])) {


I don't know if this produces adverse side effects anywhere else, but it does allow services to be used in the way you are using it.