Skip to content

Instantly share code, notes, and snippets.

View sonlichao's full-sized avatar

lichao sonlichao

  • japan
View GitHub Profile
@sonlichao
sonlichao / upload-a-file.MD
Created October 30, 2017 09:16 — forked from ahmadawais/upload-a-file.MD
Upload a file using the WordPress REST API

Upload files

Using the REST API to upload a file to WordPress is quite simple. All you need is to send the file in a POST-Request to the wp/v2/media route.

There are two ways of sending a file. The first method simply sends the file in the body of the request. The following PHP script shows the basic principle: