So where should I put this code. Should I put this in my Javascript code that I have created. I will put my whole javascript code as follows: -
try {
// Fetch the content inside the Rich Text Input (without toolbar)
var richText = document.querySelector(“#RTFF .ql-editor”).innerHTML; // Get inner HTML content
// Replace HTML tags with RTF syntax
var rtfContent = richText
.replace(/<p>/g, "\\par ") // Convert <p> to new paragraph
.replace(/<\/p>/g, "") // Remove closing </p>
.replace(/<br>/g, "\\line ") // Convert line break to RTF line
.replace(/<strong[^>]*>/g, "\\b\\cf1 ") // Convert <strong> to bold and blue in RTF
.replace(/<\/strong>/g, "\\b0\\cf0 ") // Close bold and color
.replace(/<em[^>]*>/g, "\\i ") // Convert <em> to italics in RTF
.replace(/<\/em>/g, "\\i0 ") // Close italics
.replace(/<a href="([^"]+)"[^>]*>([^<]+)<\/a>/g, "{\\field{\\*\\fldinst{HYPERLINK \"$1\"}}{\\fldrslt{\\cf1\\ul $2}}}") // Convert <a> to blue hyperlink with underline in RTF
.replace(/<[^>]+>/g, ""); // Remove any other remaining HTML tags
// Define the RTF header with the color table for blue text
var fullRtfContent = "{\\rtf1\\ansi\\deff0 {\\colortbl;\\red0\\green0\\blue255;} " + rtfContent + "}";
// Create a Blob from the RTF content
var blob = new Blob([fullRtfContent], { type: "application/rtf" });
// Create a FormData object to send the file
var formData = new FormData();
formData.append("file_url", blob, "document.rtf"); // Add the file to the FormData
// Send the file to the Bubble API
fetch("https://inconversationskz.com/version-test/api/1.1/wf/upload_file", {
method: "POST",
body: formData,
})
.then(response => {
if (!response.ok) {
throw new Error("Network response was not ok: " + response.statusText);
}
return response.json();
})
.then(data => {
console.log("File uploaded successfully:", data);
// Handle success (e.g., show a success message, update the UI, etc.)
})
.catch(error => {
console.error("Error uploading file:", error); // Error handling
});
} catch (error) {
console.error("Error generating RTF file: ", error); // Error handling
}
Thanks