Upload image to a specific Wordpress POST and field

Viewed 72

Im trying to find a way to upload an image to Wordpress custom fields using axios. so far I've been able to upload to media but i want to upload directly to a field in a post type. this is what i have so far

const axios = require('axios');
const fs = require('fs');

var config = {
    method: 'post',
    url: 'url/wp-json/wp/v2/media',
    headers: {
        'Authorization': 'Basic dsgsgshhdh',
        'Content-Type': 'application/json',
        "Content-Disposition": 'form-data; filename="example.jpeg"',
        "Content-Type": "image/jpeg",
    },
    data: fs.readFileSync('path to image', (err, data) => {
        if (err) {
            console.log(err);
        }
    }),
};

axios(config)
    .then(function(response) {
        console.log(JSON.stringify(response.data));
    })
    .catch(function(error) {
        console.log(error);
    });

the code above uploads to media but i want to upload to post type team member and field named image_url

normally with string data I post like this and pass it to my request and it works. b ut how do i post for images

var data = JSON.stringify({
    "acf": {
         "linkedin": "apo000 boys"
         "image_url": ?????
    }
 });
0 Answers
Related