upd: upload file
This commit is contained in:
22
src/module/_global/fun/delete_file.ts
Normal file
22
src/module/_global/fun/delete_file.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
export async function funDeleteFile({ name, dirId }: { name: String, dirId: string }) {
|
||||
try {
|
||||
const res = await fetch(`https://wibu-storage.wibudev.com/api/dir/${dirId}/${name}`, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
Authorization: `Bearer eyJhbGciOiJIUzI1NiJ9.eyJ1c2VyIjp7ImlkIjoiY20wdnQ4bzFrMDAwMDEyenE1eXl1emd5YiIsIm5hbWUiOiJhbWFsaWEiLCJlbWFpbCI6ImFtYWxpYUBiaXAuY29tIiwiQXBpS2V5IjpbeyJpZCI6ImNtMHZ0OG8xcjAwMDIxMnpxZDVzejd3eTgiLCJuYW1lIjoiZGVmYXVsdCJ9XX0sImlhdCI6MTcyNTkzNTE5MiwiZXhwIjo0ODgxNjk1MTkyfQ.7U-HUnNBDmeq_6XXohiFZjFnh2rSzUPMHDdrUKOd7G4`
|
||||
}
|
||||
});
|
||||
|
||||
if (res.ok) {
|
||||
console.log("Berhasil dapat");
|
||||
const hasil = await res.json()
|
||||
console.log('berhasilAmalia', hasil)
|
||||
|
||||
} else {
|
||||
const errorText = await res.json();
|
||||
console.log('errorAmalia', errorText)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Upload error:", error);
|
||||
}
|
||||
}
|
||||
24
src/module/_global/fun/upload_file.ts
Normal file
24
src/module/_global/fun/upload_file.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
export async function funUploadFile({ file, dirId }: { file: File, dirId: string }) {
|
||||
const formData = new FormData();
|
||||
formData.append("file", file);
|
||||
formData.append("dirId", dirId);
|
||||
|
||||
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 successfully");
|
||||
} else {
|
||||
const errorText = await res.text();
|
||||
console.log('errorAmalia', errorText)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Upload error:", error);
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,8 @@ import SkeletonDetailListTugasTask from "./components/skeleton_detail_list_tugas
|
||||
import SkeletonDetailProfile from "./components/skeleton_detail_profile";
|
||||
import SkeletonSingle from "./components/skeleton_single";
|
||||
import WrapLayout from "./components/wrap_layout";
|
||||
import { funDeleteFile } from "./fun/delete_file";
|
||||
import { funUploadFile } from "./fun/upload_file";
|
||||
import { WARNA } from "./fun/WARNA";
|
||||
import LayoutDrawer from "./layout/layout_drawer";
|
||||
import LayoutIconBack from "./layout/layout_icon_back";
|
||||
@@ -36,3 +38,5 @@ export { LayoutModalViewFile }
|
||||
export { globalRole }
|
||||
export { WrapLayout }
|
||||
export { NoZoom }
|
||||
export { funUploadFile }
|
||||
export { funDeleteFile }
|
||||
|
||||
Reference in New Issue
Block a user