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.
Two options:
Hook into
'wp_handle_upload'
, a filter provided by the functionwp_handle_upload()
inwp-admin/includes/file.php
:Replace the new file URI with your remote URI.
The function
wp_insert_attachment()
inwp-includes/post.php
offers two actions:You can get the attachment data by
$post_ID
and change any value here.