I'm in the progress of creating a bulk upload function for a Drupal site. Using flash I'm able to upload the files to a specific url that then handles the files. What I want to do, is not just to upload the files, but create a node of a specific type with the file saved to a filefield that has been setup with CCK. Since these are audio files, it's important that filefield handles the files, so addition meta data can be provided with the getid3 module.
Now I've looked through some of the code as I wasn't able to find an API documentation, but it's not clear at all how I should handle this. Ideally I could just pass the file to a function and just use the data returned when saving the node, but I haven't been able to find that function.
If any one has experience with this I would apreciate some pointers on how to approach this matter.
I had to do something similar some weeks ago and ended up adapting some functionality from the Remote File module, especially the
remote_file_cck_attach_file()
function. It uses thefield_file_save_file()
function from the filefield module, which might be the function you're looking for.In my case, the files are fetched from several remote locations and stored temporarily using
file_save_data()
. Attaching them to a CCK filefield happens onhook_nodeapi()
presave, using the following:$filepath
is the path to the file that should be attached,$fieldname
is the internal name of the filefield instance to use within the node and$index
would be the 0 based index of the attached file in case of multiple field entries.The function ended up within a utility class, hence the class syntax for the verifyPath() call. The call just ensures that the target directory is available:
That did it for me - everything else happens on node saving automatically.
I have not used the getid3 module yet, so I have no idea if it would play along with this way of doing it. Also, I had no need to add additional information/attributes to the filefield, so maybe you'd have to put some more information into the field array than just the file returned by
field_file_save_file()
. Anyways, hope this helps and good luck.