This code just times out

[ad_1]

I’m trying to post an HTML file to my posts section on [wordpress.org]) but the POST request juust times out

const fs = require(“fs”);
const fetch = require(“node-fetch”);

async function uploadHTMLFile() {
try {
const htmlFilePath =
“ANYHTMLFILE.html”;
const username = “USERNAME”;
const password = “API KEY”;

const formData = new FormData();
const file = fs.createReadStream(htmlFilePath);
formData.append(“file”, file);
formData.append(“status”, “pending”);
formData.append(“action”, “wp_handle_upload”);
formData.append(“title”, “title”);
formData.append(“caption”, “caption”);

const response = await fetch(“https://MYSITE.WEBSITECOM/wp-json/wp/v2/posts”, {
method: “POST”,
body: formData,
headers: {
Authorization: “Basic ” + btoa(username + “:” + password),
},
});

if (response.ok) {
console.log(“File uploaded successfully.”);
} else {
console.log(“An error occurred!”, response);
}
} catch (err) {
console.error(err);
}
}

[ad_2]

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer