Is possible to choose the file_default_scheme to save avatars? I'm using amazonS3 module and if I choose Amazon Simple Storage Service as my default download option, user's avatars are uploaded to my bucket in Amazon. I wish I could choose the default_scheme for avatars but checking the user_save function code I found these:

 if (!empty($account-&gt;picture-&gt;fid) &amp;&amp; (!isset($account-&gt;original-&gt;picture-&gt;fid) || $account-&gt;picture-&gt;fid != $account-&gt;original-&gt;picture-&gt;fid)) {
    $picture = $account-&gt;picture;
    // If the picture is a temporary file move it to its final location and
    // make it permanent.
    if (!$picture-&gt;status) {
      $info = image_get_info($picture-&gt;uri);
      $picture_directory =  file_default_scheme() . '://' . variable_get('user_picture_path', 'pictures');


So I think that it uses the default scheme selected. Is it possible to change it?

Thanks
file_default_scheme() returns a variable using variable_get(), unfortunately it just returns it straight without hooking out to any other modules.

For modules that call user_save() directly I don't see any way around this without patching the user module, there's just no way to intercept it.

For the user profile and registration forms you might be able to override the submit handlers, and call your own version of user_save() which contains logic to choose the right file scheme. I don't have time to test it but it would probably look something like this:

function MYMODULE_form_alter(&amp;$form, &amp;$form_state, $form_id) {
  if ($form_id == 'user_profile_form') {
    // Remove the standard submit handler
    if(($key = array_search('user_profile_form_submit', $form['#submit'])) !== FALSE) {
      unset($form['#submit'][$key]);
    }
    // And add the custom one
    $form['#submit'][] = 'MYMODULE_user_profile_form_submit';
  }
}

function MYMODULE_user_profile_form_submit($form, &amp;$form_state) {
  // Copy the code from user_profile_submit() and change the user_save()
  // line to MYMODULE_user_save()
}

function MYMODULE_user_save($account, $edit = array(), $category = 'account') {
  // Copy the code from user_save() and change the file scheme as required.
}


There might be some caveats to that I haven't though of but hopefully it'll provide a good place to start.