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