Forum Replies Created

Viewing 2 replies - 1 through 2 (of 2 total)
  • Forum: Fixing WordPress
    In reply to: Media by rest api
    Thread Starter georgenasim

    (@georgenasim)

    Hi @bengreeley,
    Thank you very much for your reply.
    I know the REST API and the code that I made is as the following, but I donot know where I should set the image to be uploaded to my WordPress website, the image that I need to upload on cdn server

    headers.set("Content-Type","application/json");
    headers.set("Authorization","Basic "+Buffer.from(<code>${ourUsername}:${ourPassword}</code>).toString("base64"));
    headers.set("Content-Disposition","attachment; filename='public-page-logo1.png'");
    
    fetch("mywebsite/wp-json/wp/v2/media",{
       method:"POST",
       headers:headers, 
       body:JSON.stringify({
            title:"post feature image1",
            status:"publish",
            media_type:"image",
            ping_status:"open",
            alt_text:"File upload",
            caption:"Caption upload"
    
       })
    }).then((response) => response.json())
      .then((data) => console.log(data));
    • This reply was modified 2 years, 3 months ago by georgenasim.
    How to uplaod image tp wordpress by rest api
    I tried this code 
    

    fetch(“https://&#8230;./wp-json/wp/v2/media”,{
    method:”POST”,
    headers:headers,
    body:JSON.stringify({
    title:”post feature image”,
    link:”https://cdne-c&#8230;..png”,
    source_url:”https://cdne-c&#8230;..png”,
    status:”publish”,
    media_type:”image”,
    description:””

    })
    });`

Viewing 2 replies - 1 through 2 (of 2 total)