How do I store a copied file into a different field

6 replies [Last post]
thomasjackdavid
Offline
Last seen: 10 years 40 weeks ago
Joined: 2011-07-03

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.

  1. Upload flac (field_data_field_flac)
  2. Convert flac to mp3
  3. 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.

Chris Shattuck
Offline
Last seen: 10 weeks 4 days ago
Joined: 2009-08-16
Hey there! Sounds like a fun

Hey there!

Sounds like a fun module. A couple quick questions:

  1. Are you using Drupal 6 or 7
  2. Are you saving the data to a field you've added to a content type? Or are you supplying your own field definition?

Cheers,
Chris

thomasjackdavid
Offline
Last seen: 10 years 40 weeks ago
Joined: 2011-07-03
Hi Chris, Thanks for the

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.

Chris Shattuck
Offline
Last seen: 10 weeks 4 days ago
Joined: 2009-08-16
Thank you for the kind words!

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

thomasjackdavid
Offline
Last seen: 10 years 40 weeks ago
Joined: 2011-07-03
Thanks you, I'll give it ago

Thanks you, I'll give it ago and report my progress.

thomasjackdavid
Offline
Last seen: 10 years 40 weeks ago
Joined: 2011-07-03
node_load() and node_save()

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?

thomasjackdavid
Offline
Last seen: 10 years 40 weeks ago
Joined: 2011-07-03
I managed to do everything,
Add to playlist

Add to , or

Add to new playlist:

Add to playlist
This is a member-only feature
But, it's easy to become a member

Add to cart:


Loading...
Contact us

Below are the supported keyboard shortcuts for our video player.

space
Start / stop video
shift
Go to next video
shift
Go to previous video
Increase or decrease player speed by 20%
Skip ahead or go back by 15 seconds
1...9
Jump to a percentage (2 is 20%, for example)
f
Toggle full screen
Videos Pricing More Search
BuildAModule Logo Icon BuildAModule Logo Icon
Become a member!
$29
1 month
$156
6 months
10% off
$276
12 months
20% off
All memberships come with the following:
24 / 7 access to the entire 1800+ video library
An innovative video player with a rolling transcript
Extensive Drupal and cross-platform training
A thorough and thoughtful training style
Progress tracking
Take notes on specific video sections
Intuitive multi-user management
How many users?
user
Go solo with a single user, or give multiple team members access through one account and get discounts by bundling multiple users into a single membership.