Closed (fixed)
Project:
Services
Version:
6.x-2.0-beta1
Component:
Code
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
22 Feb 2010 at 01:10 UTC
Updated:
22 Feb 2010 at 01:21 UTC
Hi,
I'm using the XMLRPC service to allow a remote application to save nodes. The node-type has a CCK filefield field. My script uploads the file with file.save, which returns a fid. I then create a node object, use the fid in the CCK filefield, and save the node with node.save. However, when doing this I get the error: "Referencing to the file used in the My File field is not allowed.".
Here's a simplified example of my script:
$DX = new DrupalXmlrpc();
$DX->userLogin();
// upload our file using the File Service
$file = new stdClass();
$file->uid = $author_uid;
$file->filename = "xmlrpc_file.mp3";
$file->filepath = "sites/default/files/" . $file->filename;
$file->filesize = filesize($original_file);
$file->timestamp = time();
$file->status = 1;
$file->file = base64_encode(file_get_contents($original_file));
$fid = $DX->fileSave($file); // call file.save
// create a node
$node = new stdClass();
$node->type = 'testing';
$node->status = 1;
$node->title = 'New node from xmlrpc';
$node->name = $author_name;
// Filefield for My File
$node->field_myfile_file = array(
0 => array(
"fid" => $fid,
"list" => 1,
"new" => 1,
),
);
// The error here is returned when calling node.save
$DX->nodeSave($node); // call node..save
$DX->userLogout();
Should this work, or am I going about it the wrong way?
I see that ImageField was having a similar problem which was apparently corrected in a newer version. (I'm only assuming it's related):
http://drupal.org/node/441280#comment-form
Thanks
Comments
Comment #1
ryan_courtnage commentedThe solution is to ensure the file has a "temporary" status before calling node.save.
http://drupal.org/node/376226#comment-2169216
So in my script, I simply change $file->status = 1 to $file->status = 0.