upd: test upload file
This commit is contained in:
@@ -3,9 +3,11 @@ import createLogUser from "./log/fun/createLogUser";
|
|||||||
import { funGetAllmember } from './member/lib/api_member';
|
import { funGetAllmember } from './member/lib/api_member';
|
||||||
import Profile from './profile/ui/profile';
|
import Profile from './profile/ui/profile';
|
||||||
import EditProfile from './profile/ui/edit_profile';
|
import EditProfile from './profile/ui/edit_profile';
|
||||||
|
import { fileUpload } from './profile/lib/upload_img_profile';
|
||||||
|
|
||||||
export { createLogUser };
|
export { createLogUser };
|
||||||
export type { TypeUser }
|
export type { TypeUser }
|
||||||
export { funGetAllmember }
|
export { funGetAllmember }
|
||||||
export { Profile }
|
export { Profile }
|
||||||
export { EditProfile }
|
export { EditProfile }
|
||||||
|
export { fileUpload }
|
||||||
|
|||||||
21
src/module/user/profile/lib/get_dir.ts
Normal file
21
src/module/user/profile/lib/get_dir.ts
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
27
src/module/user/profile/lib/upload_img_profile.ts
Normal file
27
src/module/user/profile/lib/upload_img_profile.ts
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user