How do I store a copied file into a different field
Hello,
I have started building my first module inspired by the videos on this awesome site! :)
What I am trying to do is upload a managed lossless audio file (flac) then convert it to a lossy mp3 then save each file in its own field.
- Upload flac (field_data_field_flac)
- Convert flac to mp3
- Save mp3 to its own field field_data_field_mp3 and save the uploaded flac to field_data_field_flac
I have looked for hours if not day's for the right way to do the last step, save the new mp3 its own field. I hope all this makes sense, I would appreciate any input.
Hi Chris,
Thanks for the quick reply. I have been using Drupal for a long time now but I've always managed to build websites without having to build my own modules. I always wanted to but I think I would have ever tried to learn if I didn't stumble upon one of your videos on Youtube! :)
The module I'm building is using Drupal 7 and is trying to save the data to fields that have been created in a content type.
Thank you for the kind words! I'm glad to hear you've taken the dive into module development, it can be a lot of fun. :)
One approach to this is using node_load() the node_save() function to load the node object, modify it using your custom file data, and then save it. You can use something like a debugger, var_dump or various Devel module functions to look at the structure of the node and make sure you've set it up properly.
Let me know if that points you in the right direction.
Cheers!
Chris
Thanks you, I'll give it ago and report my progress.
node_load() and node_save() definitely put me in the right direction. I have managed to store the new mp3 in the database using file_save but I can't work out how to attach this new mp3 to a separate file_generic field.
I have tried db_merge but that seems to low level for this task, is there a simpler method?
I managed to do everything, thanks Chris.
Here are the two links that helped me the most
http://buildamodule.com/video/drupal-7-core-concepts-how-to-work-with-no...
http://buildamodule.com/blog/manipulating-an-array-in-drupal-adding-remo...
Hey there!
Sounds like a fun module. A couple quick questions:
Cheers,
Chris