Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am looking to overwrite the existing upload functionality to save the file on a remote storage service. The remote storage has an HTTP interface that allow me to post file and return an addressable URL back. The reason for doing this is that the remote storage service has large amount of space and is automatically replicated for high-availability.

I have already figured out how to send files across. However, I am not sure which hook/function I should use to overwrite the existing behavior.

share|improve this question

1 Answer 1

up vote 3 down vote accepted

Two options:

  1. Hook into 'wp_handle_upload', a filter provided by the function wp_handle_upload() in wp-admin/includes/file.php:

    apply_filters( 
        'wp_handle_upload', 
        array( 'file' => $new_file, 'url' => $url, 'type' => $type ), 'upload' 
    )
    

    Replace the new file URI with your remote URI.

  2. The function wp_insert_attachment() in wp-includes/post.php offers two actions:

    do_action('edit_attachment', $post_ID);
    do_action('add_attachment', $post_ID);
    

    You can get the attachment data by $post_ID and change any value here.

share|improve this answer
    
Thanks, wp_handle_upload seem to be the one I am looking for. –  ltfishie May 14 '12 at 5:18

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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