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&node[type]=ftritem&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.