upd: test upload file

This commit is contained in:
amel
2024-09-11 12:07:02 +08:00
parent c974954385
commit 804632bb42
3 changed files with 50 additions and 0 deletions

View File

@@ -0,0 +1,21 @@
export async function getListDir() {
try {
const res = await fetch("https://wibu-storage.wibudev.com/api/dir/cm0x8a1as0001bp5te7354yrp/list", {
method: "GET",
headers: {
Authorization: `Bearer eyJhbGciOiJIUzI1NiJ9.eyJ1c2VyIjp7ImlkIjoiY20wdnQ4bzFrMDAwMDEyenE1eXl1emd5YiIsIm5hbWUiOiJhbWFsaWEiLCJlbWFpbCI6ImFtYWxpYUBiaXAuY29tIiwiQXBpS2V5IjpbeyJpZCI6ImNtMHZ0OG8xcjAwMDIxMnpxZDVzejd3eTgiLCJuYW1lIjoiZGVmYXVsdCJ9XX0sImlhdCI6MTcyNTkzNTE5MiwiZXhwIjo0ODgxNjk1MTkyfQ.7U-HUnNBDmeq_6XXohiFZjFnh2rSzUPMHDdrUKOd7G4`
}
});
if (res.ok) {
const hasil = await res.json()
console.log("File uploaded successfully");
console.log(hasil)
} else {
const errorText = await res.text();
console.log(errorText)
}
} catch (error) {
console.error("Upload error:", error);
}
}

View File

@@ -0,0 +1,27 @@
export async function fileUpload({ file }: { file: File}) {
const formData = new FormData();
formData.append("file", file);
formData.append("dirId", "cm0x8dbwn0005bp5tgmfcthzw");
try {
const res = await fetch("https://wibu-storage.wibudev.com/api/upload", {
method: "POST",
body: formData,
headers: {
Authorization: `Bearer ${process.env.WS_APIKEY}`
}
});
if (res.ok) {
console.log("File uploaded successfullyAmalia");
const hasil = await res.text()
console.log('berhasilAmalia',hasil)
} else {
const errorText = await res.text();
console.log('errorAmalia',errorText)
}
} catch (error) {
console.error("Upload error:", error);
}
}