That would be handy. To write some code to parse through a directory and add each file as a node (with the file attached) would be a great addition.

Comments

clemens.tolboom’s picture

Status: Active » Postponed (maintainer needs more info)

This would be a nice extension.

But could you get me some code example. I haven't done any file upload yet in code that is.

mgifford’s picture

The image module has a bulk upload tool, but it is specific to images. Seems to do pretty much exactly what would be needed, but it is too specific.

clemens.tolboom’s picture

If you could find a code example which copies files from /tmp into drupal file system and then returns a file id that would be great.

We do not need a bulk file upload in a node_factory php script. The script is running on the server so there is no need to upload anything. The files are placed somehow in a working directory. Does that make sense?

Cheers

mgifford’s picture

Don't have time to do this now, but may in the future. Ended up spending the time uploading the files almost by hand. Not nice, but least there were only 200 of them.

j0rd’s picture

Version: 5.x-1.x-dev » 6.x-1.x-dev

Here's a snippet for the D6 version. This won't work for D5. Add into your node_factory.module in the node_factory_set_value function.

case 'filefield':
 // Should be an array of $paths = array('/file/one.txt', '/file/two.txt');
$paths = $value;
$value = array();
foreach($paths as $path) {
   $validators = filefield_widget_upload_validators($field);
   $files_path = filefield_widget_file_path($field);
   $value[] = field_file_save_file($path, $validators, $files_path, FILE_EXISTS_RENAME);
}
break;

You can use the code like this

$edit = node_factory_create_node('ov_windows');
$files = array('/tmp/blankfile.exe', '/tmp/me.exe');
node_factory_set_value( $edit, 'field_file', $files);
$node_return = node_factory_save_node( $edit);

I've added a bunch of things to my node_factory.module which I'll release once I settle up everything, but posting this snippet for people who can use it in the mean time.

If you're looking for a D5 version, you can take the D5 snippets from here and modify my code to make it work: http://drupal.org/node/201594

clemens.tolboom’s picture

Nice code ... I hope to have some time to check this code and to commit this.

There is on 'flaw' in that filefield will be the only field that supports multiple values :( Can we fix this for other fields too?

j0rd’s picture

What "flaw" are you talking about. My code allows for multiple files to get attached into the field.

clemens.tolboom’s picture