Files
jenna-mcp/x.ts
2025-11-10 11:24:50 +08:00

40 lines
912 B
TypeScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import fs from "fs";
// 1⃣ File yang mau diupload
const filePath = "image.png";
const apiUrl = "http://localhost:3000/api/pengaduan/upload-base64";
// 2⃣ Baca file dan ubah ke base64
const fileBuffer = fs.readFileSync(filePath);
const base64Data = fileBuffer.toString("base64");
// 3⃣ Buat payload JSON
const payload = {
data: base64Data,
mimetype: "image/png"
};
// 4⃣ Kirim ke server pakai fetch
async function uploadBase64() {
try {
const res = await fetch(apiUrl, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(payload),
});
if (!res.ok) {
throw new Error(`Request failed: ${res.status} ${res.statusText}`);
}
const result = await res.json();
console.log("✅ Upload sukses:", result);
} catch (err) {
console.error("❌ Upload gagal:", err);
}
}
uploadBase64();