Upload image to wordpress using ionic/cordova with WP REST API V2
i am building mobile application with ionic and wordpress rest api v2, how to create post with image or upload image with wp rest api? i just can create post without image.
Thanks
i am building mobile application with ionic and wordpress rest api v2, how to create post with image or upload image with wp rest api? i just can create post without image.
Thanks
you can plain javascript file upload for this with ionic framework.
const url = 'YOUR_WP_ACTION_RUL';
const form = document.querySelector('form');
form.addEventListener('submit', e => {
e.preventDefault();
const files = document.querySelector('[type=file]').files;
const formData = new FormData();
for (let i = 0; i < files.length; i++) {
let file = files[i];
formData.append('files[]', file);
}
fetch(url, {
method: 'POST',
body: formData
}).then(response => {
console.log(response);
});
});
Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.