5

I want to store all the uploaded media files on a different sub-domain on the same server (for CDN origin purpose). I think I can point drupal to upload files to this location (using the File System configuration > "Public file system path ") but how do I config it to use the correct URL? I guess I can do some htaccess redirects but it makes it more complex with multisite installation.

Does the CDN module does that?

Thanks, Bnaya

Edit: I use Media module and only needs the files uploaded by it will use the CDN, I will handle the theme files.

1

this might help you a bit: http://drupal.org/project/remote_stream_wrapper

That's for the Media module, it enables you to 'read' files from a remote system, including subdomains if i'm not mistaken. Getting the files on that remote location is another story, the CDN module also won't help you there (a tool exists to sync files, see the CDN project page), but Media Mover will. It's still in development for Drupal 7, and i'm not sure what works and what does not in Media Mover at this stage, but it's at least something. Keep track of http://drupal.org/project/media_mover linked from http://drupal.org/node/566364 . More is in development at the moment, but the future looks very good.

ps. just found this question, kinda related: How to upload static files to a remote server in Drupal 7 instead of local filesystem?

What i (at this moment) do, is sync the complete site to our CDN and then use the CDN module to only load the images from the CDN server. So i save them to the local filesystem and that's synced to a remote server. That was the easiest way for us, but other options obviously exist. (for example upload all media to 1 subdirectory inside the 'files' dir and rsync/ftp/sftp/whatever that single diretory to another server. You can set the directory to save files to for every media field, not sure about body fields at the moment. If it's on the same server, you can also just symlink to it. (if your on GNU/Linux/have the correct permissions.) (and remember to also sync the generated images to the other server, those are actually used on the display of the site)

You can then use a CDN module to actually load the image from any system when a user visits the site.

Hope this all helps a bit!

1

I'm not 100% sure of what your goal is, but I just accomplished something similar and in case it helps you here is what I was looking to do and what I did.

I am uploading all images to the /sites/default/files/images directory and I wanted them to become available via http://images.example.com/filename.jpg and display on the node via ths subdomain.

To do this I setup a virtual host in /etc/httpd/conf/httpd.conf

<VirtualHost *:80>
  ServerName images.example.com
  DocumentRoot /var/www/html/example.com/sites/default/files/images
</VirtualHost>

You can then alter your subtheme node.tpl.php to reference the attached images via this subdomain.

<?php $img = 'http://images.example.com/' . $field_image['und'][0]['filename']; ?>
<img src="<?php print $img; ?>" />

I wanted the convenience of having the variables already present in the node so I used the template_preprocess_node(...) function in template.php.

function MYTHEME_preprocess_node(&$vars) {
  $node = &$vars['node'];
  if ($node->type == 'image') {
    $base_url = 'http://image.example.com';
    $vars['image_base_url'] = $base_url;
    foreach ($node->field_image['und'] as &$image) {
      $image['url'] = $base_url . '/' . $image['filename'];
    }
  }
}

With this I can access inside the node both $image_base_url as well as $field_image['und'][0]['url']

  • $image_base_url is http://image.example.com
  • $field_image['und'][0]['url'] is http://image.example.com/filename.jpg

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.