0

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

0

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);
    });
});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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