Best Drupal CDN module?
I'm looking into a CDN solution for my site since it is hosted on the West Coast with rich media and clients on the east coast are experiencing some lag. I've narrowed it down to 2 modules that fit the bill.
Simple CDN
http://drupal.org/project/simplecdn
CDN Integration
http://drupal.org/project/cdn
Anyone have any experience working with these modules. I've came up with a list of Pros and Cons
Simple CDN
Pro
Easy to install
Supports Imagecache
Does not require Drupal core patch
Con
Does it work with core images?
Development is very slow
CDN Ingration
Pro
Well rounded
Up to date and constantly working on
Con
Does it support imagecache?
Requires a Drupal core patch
Groups:
Login or register to post comments
mod_cdn
I'm looking into this Apache module: http://www.voxel.net/labs/mod_cdn Haven't tried it yet, but seems like the simplest thing to do.
I just moved one of the sites
I just moved one of the sites I manage over to Voxel servers last night. When testing the servers I actually tried mod_cdn, especially with it screwing with json results. It also seemed to slow down Apache, and was very noticeable on pages served from Boost.
Instead my solution was a custom module hooking into page_preprocess. I just loop through an array of all outputted sections (building from the common ones + system_region_list()) and then run this preg_replace:
$pattern = '/<(img|link|script|a|style) ([^>])(src|href)[\s]?=[\s]?\"|\'((.[^\'|\"]('.$extString.'))(.*?))[\'|\"]/i';foreach ($sections as $section) {
$vars[$section] = preg_replace($pattern, '<\1 \2 \3="'.$server.'/\6"', $vars[$section]);
}
For this site $base always equals "crooksandliars.com", since we do a custom multi-site module for sites like "lnmc.crooksandliars.com".
$extString are the extensions I want to push off to the CDN, which I can modify from the settings page. Basically it's just .js|.css etc. Then $server = the cdn server.
It takes about 10ms to loop through the 13 sections on my development machine. I still want to play with it more using output buffering instead, but just haven't had the time.
I actually ran benchmarks this past weekend between this and mod_cdn and this preg_replace performed a little better without boost. With Boost enabled, I saw a huge performance boost (can't remember the exact numbers but it was somewhere around 500 rps with mod_cdn and close to 3,000 without it).
HollyIT - Grab the Netbeans Drupal Development Tool at GitHub.
parallel module
sounds like one of my experiments: http://drupal.org/project/parallel This module could be modded to use an external server although it wasn't designed to do that.
I've also been thinking about an output buffer module (split all aspects of boost into stand alone modules that hook into each other and core) so one could do hook_html_alter on the html after the entire page has been outputted... but that's a long ways off; time is valuable and I tend to spend it on Boost ATM. BTW you can use hook_boost_preprocess() to edit the html before it is saved.
<?php/**
* Edit document before it is put into the boost cache.
*
* This hook is run at right before the page is cached by boost.
*
* $GLOBALS['_boost_cache_this'] and $GLOBALS['_boost_router_item'] are useful.
* set $GLOBALS['_boost_cache_this'] = FALSE if you wish to not cache this page.
*
* @param $path
* URL path of the document
* @param $data
* String containing the data
* @param $extension
* file extension type. Use to detect what type of document your operating on.
* @return
* $data string containing the document
*/
function hook_boost_preprocess($path, $data, $extension) {
return $data;
}
?>
It runs inside boost_cache_set().
We use mod_cdn and it's
We use mod_cdn and it's great.
Though you have to tweak the default config because it tries to do way more search/replace than necessary.
The issue with JSON is that Drupal sends a lot of its Javascript as Content-Type Text/HTML which mod_cdn thinks is something that it should process. To get around this you need to move your rewrite rules out of .htaccess and into your vhost config (before mod_cdn) then use a locationmatch to tell mod_cdn to not process anything at /upload, /filefield, /imce, /sites, or /gmaps
--
Dave Hansen-Lange
Web Developer
Advomatic LLC
Great White North Office
Canada
Thanks for the tip. I give
Thanks for the tip. I give give mod_cdn a shot. Is there anything that I need to watch out for if I'm using the domain access module with multiple sub domains?
Just installed mod_cdn, it
Just installed mod_cdn, it looks promising. Only thing I noticed is that it will only CDN image files. Are you guys adding in js and swf objects also? Anyone have a configuration file I can take a look at?
Dalin, Any change I can get a
Dalin,
Any change I can get a copy of your vhost configuration for this?
mod_cdn can be a bit tricky
mod_cdn can be a bit tricky to setup. As you are discovering in this thread it can be a little overzealous in the files that it processes. First off you can restrict what it is search/replacing. Here is cdn.conf (I've reduced the list of HTML tags to link, img, object, embed and script):
<IfModule mod_cdn.c>
# mod_cdn will only CDNify links in HTML if the Content-Type of the
# object being delivered matches one that's been specified. Include
# any content-types that equate to (X)HTML; here are the standard
# ones:
CDNHTMLContentType text/html application/xhtml+xml
# Typically we want to replace links to static content, e.g., images,
# static HTML files, javascript, CSS, etc. First we have to specify
# (X)HTML tags and attributes where we'll look for links to replace.
# In general when CDNifying a site, we don't want to replace URLs in
# all the places they might occur in HTML; for example, we probably
# don't want form submissions to go through the CDN. I've left
# commented a couple of tags/attributes where there will be URLs we
# probably don't want to CDNify. Note: this list is based on that
# from mod_proxy_html 3.0.1.
# Here's the declaration for W3C HTML 4.01 and XHTML 1.0:
#CDNHTMLLinks a href
#CDNHTMLLinks area href
CDNHTMLLinks link href
CDNHTMLLinks img src
CDNHTMLLinks object classid codebase data usemap
CDNHTMLLinks embed src data
#CDNHTMLLinks q cite
#CDNHTMLLinks blockquote cite
#CDNHTMLLinks ins cite
#CDNHTMLLinks del cite
#CDNHTMLLinks form action
#CDNHTMLLinks input src usemap
#CDNHTMLLinks head profile
#CDNHTMLLinks base href
CDNHTMLLinks script src for
# Here are some legacy tags/attributes from transitional (X)HTML:
#CDNHTMLLinks frame src longdesc
#CDNHTMLLinks iframe src longdesc
#CDNHTMLLinks body background
#CDNHTMLLinks applet codebase
# You can add tags/attributes of your own if necessary.
</IfModule>
Next up the vhosts file.
DocumentRoot /somewhere/www
<Directory "/somewhere/www">
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
Include /somewhere/www/.htaccess
</Directory>
<Directory "/somewhere/www/files">
AllowOverride None
Order allow,deny
allow from all
Include /somewhere/www/files/.htaccess
</Directory>
<VirtualHost 192.0.32.10:80>
ServerAdmin webmaster@example.org
ErrorLog /somewhere/logs/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel info
CustomLog /somewhere/logs/access.log combined
ServerSignature On
#Boost rewrite rules will go here.
<IfModule mod_cdn.c>
<LocationMatch "^/(?!filefield|upload|imce|gmaps|(.*)ahah_helper|(.*)email/(.*)/field_event_email|(.*)content/js_add_more)">
CDNHTMLDocType XHTML
CDNHTMLToServer cdn.example.com
CDNHTMLFromServers example.org www.example.org
CDNHTMLRemapURLServer \.jpg$ i
CDNHTMLRemapURLServer \.png$ i
CDNHTMLRemapURLServer \.gif$ i
CDNHTMLRemapURLServer \.css$ i
CDNHTMLRemapURLServer \.js$ i
CDNActAsOrigin \.jpg$ i
CDNActAsOrigin \.png$ i
CDNActAsOrigin \.gif$ i
CDNActAsOrigin \.css$ i
CDNActAsOrigin \.js$ i
CDNHTMLLinks link href
CDNHTMLLinks img src
CDNHTMLLinks object data
CDNHTMLLinks embed data
CDNHTMLLinks input src
CDNHTMLLinks script src
</LocationMatch>
</IfModule>
# If you put the Boost rewrite rules above, then you need to put the Drupal rewrite rules here (and remove the rewrite rules from .htaccess):
# <IfModule mod_rewrite.c>
# RewriteEngine on
# RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
# RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-d
# RewriteCond %{REQUEST_URI} !=/favicon.ico
# RewriteRule ^(.*)$ %{DOCUMENT_ROOT}/index.php?q=%{REQUEST_URI} [L,QSA]
# </IfModule>
</VirtualHost>
You need to use a LocationMatch to filter out all the paths that you don't want mod_cdn to process. This includes most things AJAX as Drupal usually sends these as text/HTML and not as Javascript. This Location match needs to happen before Drupal does its URL rewrites, but after Boost does its rewrites (if you are using Boost). But since you can't have a locationmatch in a .htaccess file this means that you need to move all your rewrites into the vhost config. Note that you only need to do this if you are using Boost.
Not quite sure why we have the CDNHTMLLinks duplicated in here.
For more info on mod_cdn see here:
http://www.voxel.net/labs/mod_cdn
Take note of the FAQ about mangled JavaScript.
--
Dave Hansen-Lange
Web Developer
Advomatic LLC
Great White North Office
Canada
I should note that
I should note that @intoxication's preg_replace in the page preprocessor is probably easier than all of this
[edit: ack, wrong URL the first time]
--
Dave Hansen-Lange
Web Developer
Advomatic LLC
Great White North Office
Canada
CDN integration
The CDN integration module by Wim Leers is very complete, you have different ways to use it.
You can use it simply by saying a CDN base or you could install the server that keeps the files synchronized with the CDN, it can work with a lot of different CDN's like S3, Rackspace, ftp, directory, and many others, it keeps a database with which files are synchronized and which are not.
Also allows you to use a debug option which lets you see how it would looks like if you enable it, also has an statistics that you can add and see which files are being used in the CDN and which doesn't (both options for a profile that you enable for that only).
Also you can add many filters and processors to the server, and for example you can optimize images and files before sending them to the CDN.
Nestor
Nestor Mata
http://nestor.profesional.co.cr/es
Yes, those are very positive
Yes, those are very positive things about the CDN Integration module but does it support the Imagecache module? Will it rewrite the URLS from images generated by this module? The last I heard it does not.
yes it does
Yest, if you are using the process that runs in the server and uploads files to your CDN server and if you have the patch applied, actually it does support it
Nestor Mata
http://nestor.profesional.co.cr/es
So I got it to installed but
So I got it to installed but a couple of components in my flash are not displaying images. Curious why thats the case, the flash object is pulling image links from the DB using XML. Anyone have an idea?
you need to be careful about the types you sync
I think I know what your problem is, maybe you set your swf to be published onto your CDN server, and the swf can't contact your relative paths, make sure that one of two things:
1. Don't upload your swf file and the configuration asumes it will not try to look for it in the CDN , or
2. You pass absolute params to your swf
Nestor
Nestor Mata
http://nestor.profesional.co.cr/es
Nestor, I 've only set jif,
Nestor, I 've only set jif, jpg, and png to be pulled on mod_cdn.
Hard to say without information
Hi,
Then is difficult to say without more information, do you have the site online so we can see it?
Nestor
Nestor Mata
http://nestor.profesional.co.cr/es
Yes, you can view the staging
Yes, you can view the staging site on http://staging.modernluxury.com/
Here's the error: TypeError:
Here's the error:
Your XML is bad:
<?xml version='1.0' encoding='UTF-8'?><carousel><feature><fullArt><![CDATA[/photos/playhouse-grand-opening]]><title><![CDATA[Playhouse+Grand+Opening]]><summary><![CDATA[Partygoers+dance+to+DJ+Vice%27s+mash-ups+at+one+of+Hollywood%27s+hottest+new+clubs]]><filepath lightbox='TRUE'><![CDATA[sites/default/files/09_2009_caro_ange_splayhouse.jpg]]><feature><fullArt><![CDATA[/dining/hey-baby-food-delivery-tots]]><title><![CDATA[Oh%2C+Baby%21%3A+Food+delivery+for+tots]]><summary><![CDATA[A+Hollywood+couple+starts+a+Zone-style+service+for+little+ones%21]]><filepath lightbox='FALSE'><![CDATA[sites/default/files/ANGE_HeyBaby.jpg]]><feature><fullArt><![CDATA[/node/]]><title><![CDATA[Transformers+Private+Screening]]><summary><![CDATA[In+the+Zone%3A+Action-thirsty+Washingtonians+stepped+out+to+watch+an+advanced+screening]]><filepath lightbox='FALSE'><![CDATA[sites/default/files/09_2009_caro_dc_S_BattleZone_WASH.jpg]]><feature><fullArt><![CDATA[/dining/hot-spot-maialino]]><title><![CDATA[Maialino+Takes+Over]]><summary><![CDATA[Danny+Meyer+brings+the+meat+at+his+new+Gramercy+Hotel+resto]]><filepath lightbox='FALSE'><![CDATA[sites/default/files/12_09_caro_manh_110_maialino.jpg]]><feature><fullArt><![CDATA[/photos/jos%C3%A9-andr%C3%A9s-catering-and-ridgewells-co-launch-party]]><title><![CDATA[Co-Launch+Party]]><summary><![CDATA[A+Delectable+Affair%3A+A+kickoff+to+celebrate+Jose+Andres+Catering+%26+Ridgewells+partnership+]]><filepath lightbox='TRUE'><![CDATA[sites/default/files/12_2009_WASH_Ridgewells.jpg]]><feature><fullArt><![CDATA[/photos/laguna-dance-festival]]><title><![CDATA[Laguna+Dance+Festival]]><summary><![CDATA[Ballet+Bliss%3A+Ballerinas+and+dance+lovers+mingled+post-performance+while+sipping+some+bubbly+]]><filepath lightbox='TRUE'><![CDATA[sites/default/files/OC_LagunaDance.jpg]]>None of your XML tags are being closed. Also it's accessing all images via relative URLs, so those won't even hit your CDN.
HollyIT - Grab the Netbeans Drupal Development Tool at GitHub.
Yeah, I would imagine the
Yeah, I would imagine the flash won't hit my CDN. But when I turn on the CDN rules on my vhost, the flash images will appear. When I implement the rules to rewrite images, the flash will break and not show images. You can see the difference between a broken one with CDN on on http://staging.modernluxury.com and a site without mod_cdn enabled on http://www.modernluxury.com.
If you look at the XML on
If you look at the XML on your main site then it's fine. mod_cdn is screwing with the formatting, which is the problem I had using it a couple of weeks ago. They do have some suggestions at the bottom of this page that might help:
http://www.voxel.net/labs/mod_cdn
HollyIT - Grab the Netbeans Drupal Development Tool at GitHub.
CDN integration module vs SimpleCDN module vs mod_cdn
I'm the developer of the CDN integration module. Development has been slow due to an extremely heavy first semester. Yesterday, I've fixed all bugs and implemented almost all feature requests. Today I stumbled upon this post by accident.
I'm currently working on CDN integration 2.0. The goal for 2.0 is simple: make the CDN integration module kick ass. This will be done in four ways:
The first beta is already available: http://drupal.org/node/703044.
The Simple CDN requires explicit support of each module that wants to use a CDN and doesn't support putting core CSS/JS/images on a CDN.
As of yesterday, the CDN integration module also supports ImageCache.
mod_cdn may be good for certain set-ups. It's only as good as CDN integration in basic mode though:
So images (and possibly fonts) referenced from CSS served from the CDN may still be served from the Drupal web server. CDN integration in advanced mode (with the File Conveyor daemon) can rewrite the URLs in CSS files (along with many other optimizations such as optimizing images before putting them on the CDN, and so on).
Also, mod_cdn limits you to a single CDN (single domain). With the CDN integration module, it will soon be possible to have multiple domains/CDNs, just like the Parallel module can (yes, one of my goals is to make the Parallel module obsolete).
If you have any more questions on the CDN integration module, feel free to ask them in the issue queue! :)
Simple CDN can be more robust
I have used the Simple CDN module because it is very very simple to set up and it supports "Origin Pull". I disagree with your statement
I have used a patch (submitted http://drupal.org/node/642686) that allows a module to handle more than one "element" to rewrite. This allows you to create a custom module with all the rewrites that you need. You can rewrite anything with the appropriate hooks. Currently, I am rewriting aggregated css (file and images in css file), aggregated js files, inline images via input filter, images (Drupal Core), ImageCache, and paths to thickbox ImageCache preset. Simple CDN also lets you choose different CDN's for each element - if your CDN has a gzip enabled url then you can send the css and js to that CDN and images to another.
The one downside that I found using the origin pull is the imagecache processing which you have mentioned in your other posts. On first page load where all the imagecache images have not been created yet, this can cause a significant slow down since it also has to then mirror the image to the CDN. However, after that first load, everything is CDN fast. There could be some sort of cron job that primes all the images... it would be an intensive run though.
use my imagecache patch
I haven't done anything with it for a year, but it will generate all imagecache presets on node save.
http://drupal.org/node/374202
mod_cdn - javascript errors
I tried using mod_cdn and it has problems dealing with inline javascript. Apparently, the workaround is to add javascript comments around all of your javascript that is on the page. Is there a module that does this? Has anyone encounter this issue before?
I've recently worked with
I've recently worked with Arthur to make some CDN improvements to the Media Mover module, and I'm quite happy with the results. My main concern was images and S3/CloudFront, so the actual rewriting of images is taken care of in a theme override, but its a nice option for managing the pushing of files to the CDN.
You can read a bit more about my setup here:
http://colonqbang.com/content/drupal-6-cdn-setup-using-media-mover
Also, I'm working on a partial backport of D7's file path altering to Pressflow. This would allow all rewriting of ALL drupal file paths with drupal_alter(). You can track the progress of that here:
https://code.launchpad.net/~msonnabaum/pressflow/cdn
Your colonqbang.com link is
Your colonqbang.com link is dead… But I'd like to see all CDN logic in a single module (i.e. my CDN integration module), that makes it easier for developers and end-users. It doesn't make much sense to have code custom written for Media Mover to support CloudFront. Let's talk?
Also: CDN support in Media Mover only gives you CDN support for media moved files, not for Drupal core/contrib files (CSS/JS/images)!
You're missing the necessary changes to form.inc and theme.inc. Here's a full patch: http://drupalcode.org/viewvc/drupal/contributions/modules/cdn/patches/dr.... (I'm the guy who wrote the patch to bring hook_file_url_alter() to Drupal 7.)
Media Mover will move what ever you want!
Wim-
Just a quick correction - Media Mover doesn't care about what files it moves- you can point it at your Drupal files directory and have it sync the whole thing for you. See: http://24b6.net/2009/10/04/simple-cdn-media-mover-and-s3
That being said, yes let's all get on the same boat with s3/cloud front! I'd be totally happy to have an API module for this stuff- we absolutely should share this across Drupal projects!
a.
http://24b6.net
That's awesome! My apologies
That's awesome! My apologies for my ignorance.
This would allow us to sync to Amazon S3/CloudFront without File Conveyor (File Conveyor can also sync to Rackspace CloudFiles but that's an acceptable loss), and would therefore be much, much simpler to set up for many. File Conveyor can't be set up in shared hosting environments, and this can.
The approach you propose in your blog post requires an Apache rewrite rule, which will fail when the file has not yet been synced to S3! The approach I take in the CDN integration module requires a core patch and will be able to check first whether the file has actually been synced (in fact it should keep an SQLite database to track synced files, much like File Conveyor).
Since I want a single module to rule them all when it comes to CDN integration (to keep things simple for the end user), but it's clear that there are use cases to not use a CDN for everything but only for some things. For CDN integration, I'd like to provide a custom UI (actually: virtually no UI) that will do the file syncing automatically. For Media Mover, you of course want to keep people in control. It's also clear that there's a potential clash between Media Mover putting files on S3 and CDN integration doing the same.
How do you envision this?
No Apology needed
No way to keep track of all the things going on in the Drupal-sphere!
I think one thing I'd like to see are API modules for S3/Cloudfront and what ever CDN solution people are using- that way the CDN module can implement them as well as media mover.
You're right about my blog post- I need to clean that up. Also, with D7's stream wrappers, it should be possible to extend the public file stream to include a check for the existence of the file as well before redirecting to a CDN.
You're also right about providing simple solutions for end users. Though I wonder if CDNs can ever really be considered "simple" your point is well taken.
With media mover 2.0, you can actually write configurations and steps in code and then act on them just using media mover's api- you do not need to implement the media mover UI at all. This could be as simple as something like:
$configuration = new media_mover_configuration();
// define a bunch of stuff here
$configuration->steps[1] = .....
// When something happens that you want to move the file to your CDN
$configuration->run($file);
// You can do the same thing with steps
$step = new media_mover_step();
// define a bunch of stuff here
$step->settings = array( ...
$step->run($file);
I'm not suggesting that media mover replace CDN, but it seems like there could easily be some kind of shared code for the actual moving and url rewriting rules... Not sure
http://24b6.net
That's my goal, to make CDN
That's my goal, to make CDN integration simple. By creating a screencast that shows it can be done in a matter of minutes. But first the UX in setting it up must be flawless. I've already talked to Bojhan and he wants to help making the UX awesome.
And yes, clearly some code can be shared. I'll create an issue in the Media Mover issue queue, this thread is not the right place to continue the discussion.
I'm not quite sure what to do
I'm not quite sure what to do either.
Rewriting file URL's before a page is rendered feels outside the scope of Media Mover. Especially with Wim's patch where we'll be able to rewrite file paths using drupal_alter, it doesn't make sense to also have potentially Pressflow or patched-core-only code in Media Mover.
Yet at the same time, Media Mover is already storing very valuable information that's helpful when deciding which files are rewritten to which CDN/CNAME. For each file in mm's database, we have the configuration it came from, and potentially the nid the file is associated with. That means we could use things like the node type and the user who uploaded the file to make a decision about where to rewrite the url, which seems very useful to me.
So I'm torn between not taking advantage of the data Media Mover is giving us and pushing features into Media Mover that don't have anything to do with the moving and/or processing of files.
MediaMover + CDN integration + FileSyncer
Exactly. That's what the CDN integration module is/should be for.
Maybe useful, but too resource-intensive. If you need to query so much information for multiple files on your page, it becomes too expensive.
That's why I use a simple SQLite database instead in File Conveyor.
Media Mover should keep focusing on media files IMO. I only want to break away the S3 functionality into a separate FileSyncer module. Media Mover can then still store all its extra metadata, and CDN integration can then store just a simple SQLite database.
When users are using Media Mover and CDN integration, you should configure Media Mover to move files to a separate directory on the local server, and CDN integration should move it to the CDN. That's how I see it.
Thoughts?
Pretty much agreed
Sorry that this thread has sort of been hijacked. I agree that Media Mover is not the best stand alone CDN solution because it has an overhead that modules like CDN don't have. And for a CDN solution over head is not acceptable.
That being said, I can see an argument for an integration from Media Mover to the CDN module - for example, when a file has finished transcoding, notify CDN or File Conveyor that the file should now be moved.
http://24b6.net
Sorry that this thread has
Exactly.
File Conveyor can't be notified. File Conveyor knows.
Sorry, I couldn't resist :P File Conveyor knows about changes on the file system instantaneously because it uses inotify. Hence it makes no sense to notify it. It would make sense to notify the CDN integration module, which could then call the FileSync module (which would contain MediaMover's S3 functionality) to sync the file to the CDN.
Just a minute after replying
Just a minute after replying here, I noticed a new issue in the CDN Integration issue queue, asking to roll the CDN patch for PressFlow. Here's the official issue: https://bugs.launchpad.net/pressflow/+bug/516618.
I've abandoned my branch in
I've abandoned my branch in favor of Wim's:
https://code.launchpad.net/~wimleers/pressflow/hook_file_url_alter
Please follow that one instead!
I'm curious why so many
I'm curious why so many people are using origin push CDNs that require the syncing of files. It seems like such a nightmare to get working and the possibility of breaking. I'm currently testing CDN Integration on basic mode using Limelight's origin pull service and it can't be simple enough.
Because you often also do
Because you often also do some processing on the file before pushing it to the CDN. E.g. transcoding videos, optimizing images, and so on. That's harder to do with origin pull CDNs. Although it's possible with File Conveyor.
But you're absolutely right: if you're all about ease of setup, then you can't beat origin pull CDNs!
Alternative
msonnabaum's solution above is a nice workaround. I posted an alternative to it as a comment in his blog here. And it's also below:
Great post,
I was also blown away by Media mover when I first tried it.
However I use a seperate function to do what you're trying to do above. Early on in my pre_process node function I check if any of my files have been moved by calling a simple function
THEMENAME_get_media_mover_files($variables['field_file'][0], $variables['media_mover'][3]);The [3] at the end of the media mover array is the ID of the Media Mover configuration
Here's the function
/*** A function that takes a file object and a media_mover element array and set the file path to
* its media moved path on Amazon S3 or wherever it moved to.
*
* It uses the unique file_id identifier to match file with media_mover file.
*
* $file = $variables['file_image'][0];
* $media_mover = $variables['media_mover'][{id of media mover configuration}];
*
* @param &$file A reference to a Drupal file array
* @param $media_mover A media_mover file/element array
*/
function THEMENAME_get_media_mover_files(&$file, $media_mover) {
if(module_exists('media_mover_api') && $media_mover) { // If media mover is installed...
foreach($media_mover as $media) { // Loop through each media_moved file...
if($media['fid'] == $file['fid']) { // If they match (file id is a unique identifier...
$file['filepath'] = $media['complete_file']; // Replace the attached file path with the media moved file path...
}
}
}
} // THEMENAME_get_media_mover_files()
Notice that the file is passed by reference. This function takes the file you've passed it, checks if there is a media moved file with the same id, and if there is set's the filepath of the file to the path of the S3 file.
The benefit of this is that you can call this function for all filefields in your content type and there are no extra Database calls.
MaxCDN Drupal CDN with plugin
I'd recommend checking out MaxCDN's Drupal CDN. It integrates easily with a plugin, is cost-effective and it utilizes origin pull so you won't need to upload your images directly to the cdn.
Feel free to contact me directly if you have any questions.
-Kevin
Kevin, please don't insult
Kevin, please don't insult me. There is no such thing as "MaxCDN's Drupal CDN plugin". First of all, Drupal doesn't have plug-ins, but modules. Secondly, MaxCDN lists my CDN module for Drupal in their tutorial, but they don't own it, nor did they sponsor it. MaxCDN has no contribution to my CDN module whatsoever.