asset-manager-framework icon indicating copy to clipboard operation
asset-manager-framework copied to clipboard

Support for file uploads

Open johnbillion opened this issue 3 years ago • 4 comments

See #25

Work in progress

  • [x] Support for uploads via async-upload.php when the action is upload-attachment
    • Used by the media manager
  • [x] Support for uploads via async-upload.php when the action is otherwise
    • Used when uploading from the Media admin screen
  • [x] Support for uploads via the REST API
    • Used when uploading directly into a media block in the block editor
  • [ ] Inline docs
  • [ ] Readme updates

johnbillion avatar Apr 12 '21 12:04 johnbillion

You can test this against the branch of AMF WP here https://github.com/humanmade/amf-wordpress/pull/9

It's not pretty code but core makes it very hard to replace media management in a wholesale way. The crux of how this functions relies on two key things:

  • pre_move_uploaded_file filter, this receives the actual data from the $_FILES array so we can use it create the FileUpload object. Returning a value other than null also stops the file being copied to uploads so saves the request to S3. This is where we hand off to the provider to upload
  • wp_handle_upload filter is run immediately after the above filter and returns the file name and URL so I'm using a global to pass the result of the AMF provider upload to the output of this filter so we can return errors

Other updates include handling the JSON response and WP core pretty much always calling wp_insert_attachment() after an upload. We can match the local attachment post guid and the AMF attachment post guid to replace the local response data with the AMF data.

Sketchy but it's functional.

roborourke avatar May 21 '21 17:05 roborourke

@johnbillion according to the check list in the description, can I assume that you are done and happy with the implementation? Would it make sense for anyone to review this, or not yet?

tfrommen avatar Jun 17 '21 12:06 tfrommen

I don't have the time right now to review or work on this. Rob's latest commit does what we discussed in Slack a while ago which is to switch away from handling this at the various entrypoints and instead handle it at a lower level inside the upload handlers. It'll need testing and reviewing yeah.

johnbillion avatar Jun 17 '21 12:06 johnbillion

@tfrommen the implementation in the namespace.php file could be reviewed at least. I'll update this to use an interface when I get some time.

roborourke avatar Jun 17 '21 14:06 roborourke