In a node form, I upload a image to the server via ajax and before to send to the uri, I want to optimize the original image (not a image style).

How is possible that from move_upload_file that is a native php function calls to a custom class with hook_stream_wrappers

My uri:


From here:

function drupal_move_uploaded_file($filename, $uri) {
  $result = @move_uploaded_file($filename, $uri); // this function calls to custom class
  // PHP's move_uploaded_file() does not properly support streams if safe_mode
  // or open_basedir are enabled so if the move failed, try finding a real path
  // and retry the move operation.
  if (!$result) {
    if ($realpath = drupal_realpath($uri)) {
      $result = move_uploaded_file($filename, $realpath);
    else {
      $result = move_uploaded_file($filename, $uri);

  return $result;

Calls to:


 * @file
 * Implements DrupalStreamWrapperInterface.

class OSCaddieGCSStreamWrapper implements DrupalStreamWrapperInterface {
  • See stream_wrapper_register()
    – Clive
    Oct 21, 2020 at 15:58
  • Thanks @clive. And you know how can i upload to a CDN? with a file_move($file, "gs://my-image.jpg") ?? Oct 22, 2020 at 8:30


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.